javascript - 检测链接函数的结束? [英] javascript - detect end of chained functions?

查看:156
本文介绍了javascript - 检测链接函数的结束?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

今天我正在使用链式函数调用来开发一个宠物项目,并且我很好奇当链中最后一个函数执行时我该如何检测。例如:
$ b

  func1('initial data')。func2()。func3()。func4(); 

在func2-4完成'初始数据'之后,我想检测func4已经完成了。由于func4()并不总是链中的最后一个函数,例如,它可能以.func3()或.func5()结尾,或者我可以根据我正在尝试执行的操作调用函数调用,我试图想办法检测到没有更多的函数调用正在完成,但我没有得到太多。

解决方案

<



此外,如果它们没有链接:

  var v = func1('initial data'); 
v = v.func2();
v = v.func3();
v = v.func4();

您认为最后的功能是什么?每一个函数都是它自己链中的最后一个函数,但是如果你在每一步之后最后确定了一些东西,这是行不通的。



只需要创建一个函数,最终确定流程。

Today I'm working on a pet project using chained function calls, and I'm curious how I might detect when the last function in the chain is executed. For example:

func1('initial data').func2().func3().func4();

And after func2-4 have finished working on 'initial data' I'd like to detect when func4 is done. Since func4() isn't always the last function in the chain, aka it could end at .func3() or .func5() for example, or I could mix my function calls up depending on what I'm trying to do, I'm trying to think of a way to detect no more function calls are being done but I'm not getting very far.

解决方案

You can't.

Besides, if they are not chained:

var v = func1('initial data');
v = v.func2();
v = v.func3();
v = v.func4();

What would you consider to be the last function? Every function is the last function in it's own chain, but if you finalise something after each step, that won't work.

Just make a function that you call last to finalise the process.

这篇关于javascript - 检测链接函数的结束?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆