Skip to content

A Palatable Javascript Pattern

blog.j15r.com
7 pointsjoelgwebber1 comment
On HN

Comments

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.

AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.