js中原型的使用

谢天 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 )
        /* 
        想要连缀的语法 需要返回当前的函数 返回当前的调用对象等等

        在原型上写方法 写函数很方便进行调用
        原型的使用
        */
       /* 添加的方法和属性 都是可以枚举的 
       给原型进行添加 非常好使用 但是需要考虑冲突性
       */
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值