Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Javascript - Simple "Class" Instantiation (ejohn.org)
4 points by nickb on Dec 8, 2007 | hide | past | favorite | 1 comment


Checking '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




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: