[](()继承
原理是:复制父类的属性和方法来重写子类的原型对象
原型继承
构造函数继承
组合继承
寄生继承
寄生组合继承
class
等等
// 寄生组合继承方法
function Father(…arr) {
this.some = ‘父类属性’;
this.params = arr;
}
Father.prototype.someFn = function() {
console.log(1);
}
Father.prototype.someValue = ‘2’;
function Son() {
Father.call(this, ‘xxxx’);
this.text = ‘2222’;
}
Son.protptype = Object.create(Father.prototype);
Son.prototype.constructor = Son;
[](()Object,create做了什么
Object._create = function(obj){
function F(){}; // 创建了一个新的构造函数F
F.prototype = obj; // 然后将构造函数F的原型指向了参数对象obj
return new F(); // 返回构造函数F的实例对象,从而实现了该实例继承obj的属性。
}
[](()闭包
闭包就是有权访问一个函数内部变量的函数,也就是常说的函数内部嵌套函数,内部函数访问外部函数变量