原型:prototype fn.prototype ===> fn.prototype.__proto__ ===constructor.prototype
构造函数具备
隐式原型:([[prototype]]) 私有状态
__proto__ obj.__proto__
对象才具备
[].__proto__ ===Array.prototype.__proto__ === object.prototype =null
使用场景:
1、封装同一个构造函数的衍生对象的公共方法
function Person(){}
obj = new Person()
obj = new Person()
obj = new Person()
Array.prototype
a=[]----new Array()
swiper.prototype.xxx
2、es5 继承(类的继承)
基于原型的继承
function Animal(){} 公共操作
Dog.prototype =new Animal();
原型链紊乱:
Dog.prototype.constructor = Dog
function Dog(){}
call aplly 实现继承
call()
function Animal(){}
function Dog(){
// dog this --> 指向animal的this
Animal.aplly(this)
Animal.call(this)
}
原型直接继承:
function Animal(){}
function Dog(){}
Dog.prototype = Animal.prototype
原型链紊乱:
Dog.prototype.constructor = Dog
3、es6 关键字 extends
原型链:
描述隐式原型与显示原型的关系链 (对象构建过程中的关系链)
继承
object