I'm not that into dynamic programming languages but rather I've composed something reasonable of JavaScript code. I never truly got my head around this prototype-based programming, does anybody know how this works?
var obj = new Object();
obj.prototype.test = function() { alert('Hello?'); };
var obj2 = new obj();
obj2.test();
I recollect a lot of conversation I had with individuals some time back (I'm not by and large sure the thing I'm doing) but rather as I get it, there's no understanding of a class. It's simply an object, and instances of those objects are clones of the first, correct?
In any case, what is the specific goal behind this ".prototype" property in JavaScript? How can it identify with starting up 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