如何在没有链接的情况下调用函数链中的任何函数?
抱歉,如果我的问题不够清楚。我将把我的代码放在这里...
var chain = {
'fn_1' : {
//fn_1 code here
chain.fn_2();},
'fn_2' : {
//fn_2 code here
chain.fn_3();}
...and so on
}
假设我想调用 chain.fn_1(),有没有办法可以在不调用 chain.fn_2() 的情况下做到这一点?
我现在能想到的是一个标志,但是每个函数可能都会有很多多余的标志。你们有什么想法吗?
Sorry if my question wasn't clear enough. I'll put my code here...
var chain = {
'fn_1' : {
//fn_1 code here
chain.fn_2();},
'fn_2' : {
//fn_2 code here
chain.fn_3();}
...and so on
}
Let's say if i wana call chain.fn_1(), is there a way I can do that without calling chain.fn_2()?
What I can think of right now is a flag, but that would be alot of excess flags probably for each function. Do you guys have any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果这一系列函数每个都调用下一个函数,那么您是正确的,那么您需要某种标志。很可能,最好的方法是修改您的函数,以便它们返回对对象的引用。然后你可以像这样链接:
If the series of functions each call the next one you're correct, you'd need to have some sort of flag. In all likelihood, what would be best would be to modify your functions so that they return the reference to the object. Then you could chain like so:
gddc 的答案是最好的,但是如果您由于某种原因无法修改对象,您可以这样做:
g.d.d.c's answer is best, but if you can't modify the object for some reason, you could do this: