对象可以定义属性来使用自己的方法吗?
点这个
obj = {
prt:function(){console.log("HELLO")}
prt0:obj.prt()
}
我想要 obj.prt0 -> "HELLO"
最佳答案
var obj = {
prt:function(){
console.log("HELLO")
return "HELLO";
},
prt0: function(){
this.prt()
}
}
obj.prt0; //do nothing, it is only a method
obj.prt0(); //execute method, will print Hello
关于javascript - 对象在javascript中使用自己的方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56122351/