lundi 22 décembre 2014

What is purpose of the javascript constructor prologue?

I often come across the following constructor prologue in many node.js/javascript sources.



function MyClass () {
// prologue
if (!(this instanceof MyClass)) {
return new MyClass();
}
// do actual constructor logic
}


Could you please explain what is this for? Thanks.


Aucun commentaire:

Enregistrer un commentaire