Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Basically he’s just using JavaScript’s built-in objects and making the initializer function call the prototype's init. The advantage vs. Crockford’s "module pattern" is that if you plan to make many instances, the functions don’t all need to be recompiled every time, or take up extra memory.

I would advise the GP poster to pick up some class implementation (or roll his own), and use some bind function instead of all the `self`s (if only because other JavaScript programmers will recognize the style better). One that seems to work reasonably well for simple use cases is John Resig’s suggestion, http://ejohn.org/blog/simple-javascript-inheritance/ though one thing to keep in mind with that implementation (just as with the poster's) is that new instances must be created with `new`.

That one is supposedly inspired by base2: http://code.google.com/p/base2/source/browse/trunk/lib/src/b...

However you decide to do it, the prerelease versions of Resig’s upcoming book are quite helpful in understanding how these designs work and all the tricky corners of JavaScript closures and object inheritance.



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

Search: