Probably the most short question. What if I have these code and I want to stop executing any further after specific point inside jQuery document ready. Does return will do the job in any case?

$(function(){

return; //stop executing any further.

alert('passed 1');

(function(){
  alert('passed 2');
})();

check();

});

function check(){
 alert('passed 3');
}
有帮助吗?

解决方案

return will stop the execution of the function in which you are calling it directly.

So yes, it will work in your case, unless you are putting it in the other two functions (check or the self-executing one) - in that case it will of course only stop the execution in the function you have put it into.

I must warn you that this is not a very good practice in most cases. Easily leads to code that is not pleasant to read and not easy to follow.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top