I'm not that in to dynamic programming but I've written my fair share of JavaScript code. I never really got my head around this prototype-based programming, does any one who know how this works?
var obj = new Object();
obj.prototype.test = function() { alert('Hello?'); };
var obj2 = new obj();
obj2.test();
I remember a lot talk I had with people a while back, I'm not actually sure what the hell I'm doing. As I understand it, there's no concept of a class, it's just an object, and instances of those objects are clones of the original, right?
But what is the exact purpose of this ".prototype" property in JavaScript? How does it relate to instantiating objects?
Update: correct way
var obj = new Object(); // not a functional object
obj.prototype.test = function() { alert('Hello?'); }; // this is wrong!
function MyObject() {} // a first class functional object
MyObject.prototype.test = function() { alert('OK'); } // OK
Also these slides really helped a lot.