what exactly is “call”/“apply” doing here?
本问题已经有最佳答案,请猛点这里访问。
1 2 3 4 5 6 7 8 9 10 11 12 13 | each: function( object, callback, args ) { ... if ( callback.apply( object[ name ], args ) === false ) { break; } ... if ( callback.call( object[ i ], i, object[ i++ ] ) === false ) { break; } return object; } |
你可以忽略代码,也许……它的jquery.jquery中的每个实现
我想知道这条线是干什么的
我的意思是这些构造试图检查什么条件?
We can break the
$.each() loop at a particular iteration by making the callback function returnfalse . Returning non-false is the same as acontinue statement in a for loop; it will skip immediately to the next iteration.
所以,这段代码:
1 2 3 | if ( callback.apply( object[ name ], args ) === false ) { break; } |
检查函数是否返回
如果跳过上下文部分,代码可能如下所示(在ES6中):
1 2 3 | if (callback(...args) === false) { break; } |