zoukankan      html  css  js  c++  java
  • JS数组的forEach方法(兼容所有浏览器)

    
    
    //->自己在内置类的原型上扩展一个myForEach来处理forEach不兼容的问题
    //callBack:回调函数,遍历数组中的一项,就要执行一次callBack
    //context:改变callBack方法中的this指向

    Array.prototype.myForEach = function myForEach(callBack, context) {

    typeof context === "undefined" ? context = window : null;

    if ("forEach" in Array.prototype) {
    this.forEach(callBack, context);
    return;
    }

    //->不兼容处理
    for (var i = 0; i < this.length; i++) {
    typeof callBack === "function" ? callBack.call(context, this[i], i, this) : null;
    }
    };




    
    
     
  • 相关阅读:
    LeetCode90.子集 ||
    Ubuntu下的Matlab安装
    FAQ
    青石板
    交叉熵损失函数
    tf常用函数
    激活函数
    SGD和GD的区别
    卷积神经网络
    Ubuntu安装Matlab2016b
  • 原文地址:https://www.cnblogs.com/wangying731/p/5164642.html
Copyright © 2011-2022 走看看