prototype
原型,通过设置对象的prototype的内容来设置需要被实例化的内容
_proto_
原型链,可以通过对象的_proto_查找实例的构造函数的prototype属性,以及继承的其他构造函数的prototype属性
construct
表示构造函数,是实例化或者继承后的构造函数
实现js继承和实例化
1.继承
function Cat(name){
Animal.call(this);
this.name = name || 'Tom';
}
(function(){
// 创建一个没有实例方法的类
var Super = function(){};
Super.prototype = Animal.prototype;
//将实例作为子类的原型
Cat.prototype = new Super();
})();
// Test Code
var cat = new Cat();
console.log(cat.name);
console.log(cat.sleep());
console.log(cat instanceof Animal); // true
console.log(cat instanceof Cat); //true
该实现没有修复constructor。
Cat.prototype.constructor = Cat; // 需要修复下构造函数