原型&原型链

三个属性

constructor:构造函数
proto:存在于对象,是对象的内置属性,指向原型
prototype: 存在于函数,显示修改对象的原型属性

原型链

  1. 一般对象F(指对象不是由Object和Function创建处理的)
console.log('====一般对象函数F & 构造器创建对象===')
function F(){
	
}
let f = new F()
console.log(f.__proto__ === F.prototype) // true
console.log(F.prototype.constructor === F) // true
console.log(F.prototype.__proto__ === Object.prototype) // true
console.log(F.__proto__ === Function.prototype) //true
  1. Object()
console.log('====Object===')
let obj = new Object()
console.log(obj.__proto__ === Object.prototype) // true
console.log(Object.prototype.constructor === Object) // true
console.log(Object.prototype.__proto__ === null) // true
console.log(Object.__proto__ === Function.prototype) // true
  1. Function()
console.log('====Function===')
let fun  = new Function()
console.log(fun.__proto__ === Function.prototype) // true
console.log(Function.prototype.constructor === Function) // true
console.log(Function.prototype.__proto__ === Object.prototype) // true
console.log(Function.__proto__ === Function.prototype) // true
  1. 字面量
console.log('====字面量===')
let a = {}
console.log(a.__proto__ === Object.prototype) // true
console.log(a.__proto__ === a.constructor.prototype) // true
  1. Object.create
console.log('====Object.create===')
let b = {name:'zyy'}
let c = Object.create(b)
console.log(c.__proto__ === b) // true
console.log(c.__proto__.__proto__ === Object.prototype) // true
console.log(c.__proto__.prototype) // undefined

你可能感兴趣的:(javacript)