Sunday 21 August 2011

OOP Javascript

creating a class with inheritable properties and accessing them.

var A = function(){}; // This is the constructor of "A"
A.prototype.constructor = A;
A.prototype.value = 1;
A.prototype.test = function() { alert(this.value); }
var a = new A(); // create an instance of A
alert(a.value);  // => 1
alert(a.test()); // => 1


http://www.ruzee.com/blog/2008/12/javascript-inheritance-via-prototypes-and-closures

No comments:

Post a Comment