开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜