Dmi*_*nov 1 javascript node.js
在创建类和使用类方法之后,我只想在onсe上调用构造函数.我如何在JavaScript中执行此操作?谢谢!
var Test=function(){
//hello(); // why not working? How call?
}
Test.prototype.hello=function(){
console.log(1);
}
var t=new Test();
t.hello()
Run Code Online (Sandbox Code Playgroud)
在构造函数中,您可以通过this关键字访问对象的方法:
var Test=function(){
this.hello();
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
62 次 |
| 最近记录: |