r/javascript • • May 28 '19

What are some JavaScript things beginners don't know?

333 Upvotes

383 comments sorted by

View all comments

Show parent comments

3

u/theycallmeepoch May 28 '19

What is the advantage to using a function instead of declaring the pencil as an object with its own properties and methods?

4

u/circlebust May 28 '19

You use a function to create such an object if you want an object (ES6 Classes are just syntactic sugar over functions), but the other way around doesn't work if you ever want more than one single pencil in your program.

1

u/mkymonkey May 29 '19

What happened to pen?

1

u/[deleted] May 31 '19

The pen factory got used to create a pencil by leveraging closure?