讲干货,不啰嗦,经过prototype能够获取到JavaScript的原型对象,进而能够在对象原型上添加新的属性和方法,当该方法与原方法名称同样时会覆盖原方法既:重写,当不同时既:添加数组
如:实现数组Array的push方法的重写this
Array.prototype.push = function() { for( let i = 0 ; i < arguments.length ; i++){ this[this.length] = arguments[i] ;//arguments为传参数组列表 } return this.length; }
能力有限,水平通常,错误之处,欢迎指正,感谢关注和评论!spa