我正在尝试使用变量替换让 javascript 链接工作。无法让它发挥作用。感谢帮助。
var Class = function() {
this.one = function() {
alert('one');
return this;
}
this.two = function() {
alert('two');
return this;
}
if (this instanceof Class) {
return this.Class;
} else {
return new Class();
}
}
var test = new Class();
// this works
test.one().two();
var func = '.one().two()';
// want to make this work
test[func];
最佳答案
没有名为“.one().two()”的函数
试试这个,
test['one']()['two']();
编辑: 我相信您仅将其用于学习目的,而不是用于生产站点。
关于Javascript 链接和变量替换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12242486/