ASCII码 ASCII码

JavaScript学习笔记(二十二)——原型及原型链

发布于:2021-12-19 10:21:39  栏目:技术文档

  原型prototype

  function Person() {}

  console.log(Persontotype) // 是一个对象

  function Person() {}

  ?

  Persontotype.name='prototype'

  Persontotype.sayHi=function () {}

  __proto__

  function Person() {}

  ?

  var p1=new Person()

  ?

  console.log(p1.__proto__===Persontotype) // true

  function Person() {}

  ?

  Persontotype.sayHi=function () {

  console.log('hello Person')

  }

  ?

  var p1=new Person()

  p1.sayHi()

  function Person() {}

  ?

  Persontotype.sayHi=function () {

  console.log('hello')

  }

  ?

  var p1=new Person()

  var p2=new Person()

  ?

  console.log(p1.sayHi===p2.sayHi)

  原型链

  一个对象所属的构造函数

  // 数组本身也是一个对象

  var arr=[]

  var arr2=new Array()

  // 函数本身也是一个对象

  var fn=function () {}

  var fun=new Function()

  constructor链状结构原型链的访问原则对象的赋值总结

相关推荐
阅读 +