Inheritance...

lfanele's icon

Hi,
I think I'm going cracy. I wanted to write my own objects, but for some reason I can't get inheritance to work in js. I've read about javascript-inheritance on the web before and boiled it down to a simple example, but when you run the code i always get an x undefined...

Is there something obvious i am missing?

Thanks a lot, Stephen

//inheritance revisited

autowatch = 1;

var sub = new Subclass();

bang();

function bang() {
    post("inherited x: "+sub.x+"n");
// this should print 244 right?
}

// my SuperClass
function Superclass() {
this.x = 244;
}

// SubClass inherits from SuperClass ?
function Subclass(){
}

Subclass.prototype = new Superclass();