...

View Full Version : Accessing a value from a "parrent" class



ken_shoti
05-07-2009, 09:31 AM
Given this piece of code, is there a way for "child" to get the value 3.14


function parentClass() {
this.CONSTANT=3.14;
};

parentClass.child=function() {
alert(parentClass.CONSTANT); //how to make it get 3.14
};

x = new parentClass.child(1);

Thanks

oesxyl
05-07-2009, 09:25 PM
Given this piece of code, is there a way for "child" to get the value 3.14


function parentClass() {
this.CONSTANT=3.14;
};

parentClass.child=function() {
alert(parentClass.CONSTANT); //how to make it get 3.14
};

x = new parentClass.child(1);

Thanks


function A(){
this.PI = 3.14;
};

function B(){};
B.prototype = new A();

var x = new B();
alert(x.PI);

http://www.javascriptkit.com/javatutors/oopjs.shtml
http://www.javascriptkit.com/javatutors/object.shtml
http://www.javascriptkit.com/javatutors/proto.shtml
http://www.webreference.com/js/column34/
http://www.webreference.com/js/column80/index.html
http://www.webreference.com/js/column79/
http://www.webreference.com/programming/javascript/rg25/index.html

best regards

rnd me
05-08-2009, 03:00 AM
Given this piece of code, is there a way for "child" to get the value 3.14

Thanks





function parentClass() {
this.CONSTANT=3.14;
};

parentClass.prototype.child=function() {
alert(this.CONSTANT); //how to make it get 3.14
};

x = (new parentClass).child(1);


you were close, changes in red.

ken_shoti
05-08-2009, 06:35 AM
Thanks for the corrections :)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum