Hacker News new | comments | show | ask | jobs | submit login
A Palatable Javascript Pattern (j15r.com)
7 points by joelgwebber 1278 days ago | hide | past | web | 1 comment | favorite



This pattern is egregious and shows a lack of knowledge of the architecture and language.

All these private methods are going to be duplicated for every object created. The whole point of the 'this' magic in javascript is to allow the same function, ie. the same memory usage, to be used with 1000s of objects with no hit. Here, you're going to get unique functions, extra memory, for just having the 'this' operator substituted by a variable named _elem. This code is fundamentally flawed and I severely suggest to never use closures for shared object methods when instead a shared method that is bound using '.bind' will ensure much better performance and memory usage.




Guidelines | FAQ | Support | API | Security | Lists | Bookmarklet | DMCA | Apply to YC | Contact

Search: