后盾人:JS课程第十一章(原型)

1.原型

 原型体现

    let arr = [] //new Array
    console.log(arr.__proto__ == Array.prototype); //true

  //同理,也适用{}-Object、“”-string、123-number、true-Boolean、/a/i - RegExp..

Object.setprototypeOf(a, b)    //修改 a 对象原型__proto__为 b 。第一个为被设置对象,第二个为原型父级

Object.getprototypeOf( a )      // a 对象原型

a.constructor           //找到 a 对象父级原型

a instanceof b          //检验 b 是否在 a 的所有原型链中 返回布尔

 b.isPrototypeOf( a )          // b 是否在 a 的原型链上  返回布尔

Object.create( a )        //创建一个新对象,并用a作为新的proto

mixin 多继承

object.assign( 对象, 属性)   //合并对象和属性    

super = this.__proto__ 

posted @ 2021-09-07 17:34  人才不才  阅读(53)  评论(0编辑  收藏  举报