I'm trying to understand how the prototype property works, but there is one thing I donť get:
As far as I've got it, when I have one custom object with some methods and properties, all instances of this object point to its definition without copying (as the object was constructed with 'this'). To make it more clear what I mean (simplified):
Now assuming all of the instances point to the same method, is there a way to make them work independently? Again to make it more clear, let's say I have a timer object defined (with a prototype method for interval). I add two instances of the timer object to a page and I want them to work independently, just as they do not know of each other. It works okay when I use 'this' instead of prototype for the interval method, but when I use prototype, it seems to be broken (only the second instance counts). Is it because the both instances point to the same method and this feature just cannot be used this way? I could not find any relevant answer to this.
I also apologize, the question may be confusing and my english is not that good.
Thank you.
As far as I've got it, when I have one custom object with some methods and properties, all instances of this object point to its definition without copying (as the object was constructed with 'this'). To make it more clear what I mean (simplified):
Code:
// obj definition myObject myObject.prototype.method myObject.prototype.property // this is probably clear, those are just variables // now instances: aa = myObject aa.method bb = myObject bb.method cc = myObject cc.method
I also apologize, the question may be confusing and my english is not that good.
Thank you.
Comment