Hacker News new | past | comments | ask | show | jobs | submit login
A Palatable Javascript Pattern (j15r.com)
7 points by joelgwebber on Aug 24, 2013 | hide | past | favorite | 1 comment



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.




Consider applying for YC's Spring batch! Applications are open till Feb 11.

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

Search: