Saturday, July 25, 2009

Object oriented JS

I was going th the object oriented js and below is the basic example

function base (){};{
alert('base prototype foo');

var b = new base(); = function(){alert('');};

function sub(){};

function subsub(){};
subsub.prototype= new sub();

function sss(){};
sss.prototype=new subsub();

function test(){
//var b = new base();
alert('\n' +;
//alert('b.prototype foo\n' + b.prototype);
//var s0 = new sub();
//alert('\n' +;
var ss= new sss();
alert( '\n' +;

base is extended by sub, which is further extended by subsub. We create a new instance of this subsub and call the inherited method. simple.

No comments:

Post a Comment