browserify / browserify-handbook

how to build modular applications with browserify
Other
4.58k stars 292 forks source link

"constructor tip" references? #60

Open perguth opened 8 years ago

perguth commented 8 years ago

At least I would like to read more on that topic touched upon in the constructor tip in the reusable compontens section.

emilbayes commented 7 years ago

It's to do with checking that the context, this, is an instance of the object Widget, ie. called with new. You can read more about what the new keyword does here 😄 https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/new

Another point worth noting is that if nothing is returned for the constructor, the newly created object is returned. This means you can freely choose to return something else if you want to. However this is rarely seen, but applicable in some special cases.