There are two types of event propagation in Dom, one is capture (from parent node to child node), one is bubbling (from child node to parent node), so one event can have multiple processors to handle it, and the DOM standard contracts return False to prevent the event from continuing to propagate.
Each in jquery replaces Break;return ture with return false instead of continue.
function A () {
if (true) {
//
return true;
}
}
In a function there is a each, and in each case a condition is set, the function returns True or FALSE.
However, break and continue cannot be used within each block, and the function of break and continue should be used in other ways.
Break----with return false;
Continue--with return ture;
So in each case, when you want to use return true to return to this function, you just let each continue execution and
Even if each is not interrupted, the function cannot return.
Since each of jquery is implemented by looping through callback functions, the break that is written within the function only applies to the logic inside the function, and does not work on the outer loop of the function, so break doesn't work. Specifically, we can analyze the source code of jquery, following the example of each method in jQuery2.1.4:
Each :function(obj, callback, args) {varvalue, I= 0, Length=Obj.length, IsArray= Isarraylike (obj);//true if obj is an array-like structure (available for traversal) if(args) {if(IsArray) { for(; i < length; i++) {Value= Callback.apply (obj[i], args);//Loop Call if(Value = = =false) {//if the return value is all equal to (including type and value) False, exit the loop Break; } } } Else { for(Iinchobj) {//This is an object that needs to be traversed with a forValue =callback.apply (obj[i], args); if(Value = = =false ) { Break; } } } //A Special, fast, case for the most common use of each}Else { if(IsArray) { for(; i < length; i++) {Value=Callback.call (obj[i], I, obj[i]); if(Value = = =false ) { Break; } } } Else { for(Iinchobj) {Value=Callback.call (obj[i], I, obj[i]); if(Value = = =false ) { Break; } } } } returnobj;} It can be seen from the source that only the callback function returns a value of False to exit the loop.
Blog Source: http://www.cnblogs.com/wyaocn/p/5827369.html
JavaScript return False