tem*_*ame 3 javascript methods object
我遇到的情况是必须能够通过两个不同的名称来调用对象上的方法,而我发现这样做的最短路径是这样的:
var c = {
a : function() {console.log("called a!");}.
b : function() {this.a();}
};
Run Code Online (Sandbox Code Playgroud)
我当时希望有类似的东西:
var c = {
a,b : function() {console.log("called a!");}.
};
Run Code Online (Sandbox Code Playgroud)
但到目前为止,我的研究还没有发生过类似的事情.有没有更好的方法?
您可以稍后分配b:
var c = {
a : function() {console.log("called a!");}.
};
c.b = c.a;
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
46 次 |
最近记录: |