如何在javascript中创build类后运行函数
我只想在创build类和使用类方法之后调用构造函数。 我怎么能在JavaScript中做到这一点? 谢谢!
var Test=function(){ //hello(); // why not working? How call? } Test.prototype.hello=function(){ console.log(1); } var t=new Test(); t.hello()
https://jsfiddle.net/dmitriykupriynov/doo6bj0b/
在构造函数中,你可以通过this
关键字来访问对象的方法:
var Test=function(){ this.hello(); }