gpt4 book ai didi

Javascript 元编程

转载 作者:数据小太阳 更新时间:2023-10-29 05:44:54 28 4
gpt4 key购买 nike

有没有办法在 javascript 中指定类似下面的内容?

var c = {};
c.a = function() { }

c.__call__ = function (function_name, args) {
c[function_name] = function () { }; //it doesn't have to capture c... we can also have the obj passed in
return c[function_name](args);
}

c.a(); //calls c.a() directly
c.b(); //goes into c.__call__ because c.b() doesn't exist

最佳答案

Mozilla 实现了 noSuchMethod但除此之外……不。

关于Javascript 元编程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3858415/

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