gpt4 book ai didi

Javascript 链接和变量替换

转载 作者:行者123 更新时间:2023-11-29 20:05:21 26 4
gpt4 key购买 nike

我正在尝试使用变量替换让 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com