3 ms·
Javascript - Simple "Class" Instantiation
- axod 19y agoChecking 'this instanceof' on every single call to the function seems a bad idea to me, not to mention having the function call itself again to construct the object. If you use the function as it was intended, you won't have problems. I have to say it's not been a 'debugging nightmare' for me... >> "So there you have it: A simpler syntax for classical-style object instantiation that easy for end users and is more robust and resilient to misuse." I guess if you do prefer classical-style, and are prone to misusing things, it could be handy. Far easier just to make your constructors start with uppercase. function Foo() { // This is a constructor, starts with 'F' function foo() { // This isn't a constructor