谢天 0515 原型的使用还需要看 后续
0515 {
原型
继承
深复制
}
/* 原型的使用 */
console.log( Array.prototype )
Array.prototype.abc = function(){
console.log('asda')
}
let arr = [12,3,13123,2];
// arr.abc();
/* 实现foreach */
Array.prototype.forEach1 = function(fn){
for(let i = 0;i < this.length;i++){
fn(this[i],i,this)
}
}
arr.forEach1(function(item,index,arr){
console.log(item,index,arr)
})
/* 判断类型 可以使用constructor 看他的构造函数 */
let str = '12313';
let str1 = new String(str);
console.log( str.constructor == String )
console.dir( str1 )
console.log( str instanceof String )
console.log( str1 instanceof String )
/*
想要连缀的语法 需要返回当前的函数 返回当前的调用对象等等
在原型上写方法 写函数很方便进行调用
原型的使用
*/
/* 添加的方法和属性 都是可以枚举的
给原型进行添加 非常好使用 但是需要考虑冲突性
*/
js中原型的使用
最新推荐文章于 2022-10-25 19:09:33 发布