zoukankan      html  css  js  c++  java
  • 自学前端开发:模拟Array功能 不是扩展子类

    function MyArray(){};//创建模拟数组功能的构造函数

                        MyArray.prototype.length=0;//解决IE下使用扩展子类 数组length的bug

                        (function(){

                            var methods=['push','pop','shift','unshift','slice','splice','join'];

                            for(var i=0;i<methods.length;i++){

                                (function(name){

                                    MyArray.prototype[name]=function(){

                                        return Array.prototype[name].apply(this,arguments);

                                    };

                                })(methods[i]);//根据传进来的methods值 来继承Array

                            }

                        })();

                        var mine=new MyArray();

                        mine.push(1,2,3,4);

                        console.log(mine.length);

  • 相关阅读:
    Wiggle Sort II
    Coin Change
    MPLS LDP 知识要点
    MPLS Aggreate & Untag
    Lab MPLS隐藏标签显示
    Lab MPLS过滤标签转发
    MPLS MTU Aggregation
    研究MPLS MTU的问题
    Lab 利用MPLS解决BGP路由黑洞
    MPLS 标签保留
  • 原文地址:https://www.cnblogs.com/xsns/p/6806576.html
Copyright © 2011-2022 走看看