JS OOP calling a method from the constructor
How do I call a method from inside my class' constructor in JavaScript?
I have the following Class:
function Aclass(){
this.classValues = this.classMethod.call();
}
Aclass.prototype.classMethod = function(){
return 'Hello World';
}
I initialize the class:
var test = new Aclass();
I get the following error:
Aclass.prototype.classMethod is 开发者_如何学编程undefined
I'm a newbie with JS OOP and would really appreciate a nudge in the right direction.
Thanks.
Did you put the line
var test = new Aclass();
Before the rest of your code? That would result in the error you described.
精彩评论