i’v been using javascript getters for a long time in my applications, and always thought
that they work like this:
myobject.prototype.__defineGetter__('something', function () {
return DoSomeHeavyComputation() // this will be executed only once and will be saved
})
new myobject()
myobject.something // the computation will be done here
myobject.something // no computation will be done here.
i just found out the computation is done each time…
is there a resource or something that shows how do they actually work ?
This article is awesome and gets really into the nitty-gritty of prototyping and object instantiation: http://dmitrysoshnikov.com/ecmascript/chapter-7-2-oop-ecmascript-implementation/