zoukankan      html  css  js  c++  java
  • return true 与 return false的妙用——jQuery

    var arr = [1, 3, 5,7,9];
    jQuery.each(arr, function(key, value){
        if(key === 2){
            return true;
        }
        console.log(key,value);
    }) ;

    上段代码等价于:

    var arr = [1, 3, 5,7,9];
    jQuery.each(arr, function(key, value){
        if(key === 2){
            continue;
        }
        console.log(key,value);
    }) ;

    执行效果如下:

    var arr = [1, 3, 5,7,9];
    jQuery.each(arr, function(key, value){
        if(key === 2){
            return false;
        }
        console.log(key,value);
    }) ;

    上段代码等价于:

    var arr = [1, 3, 5,7,9];
    jQuery.each(arr, function(key, value){
        if(key === 2){
            break;
        }
        console.log(key,value);
    }) ;

    执行效果如下:

    不考虑业务场景,一味的争执技术的高下,都是耍流氓。
  • 相关阅读:
    加载声音的过程
    onkeyup,onkeydown和onkeypress
    加载着色器的异常

    3
    1
    1
    java总结
    环路
    own address as source address
  • 原文地址:https://www.cnblogs.com/leoych/p/14860396.html
Copyright © 2011-2022 走看看