1、继承第一种方式:对象冒充
2、继承第二种方式:call()方法方式
3、继承的第三种方式:apply()方法方式
4、继承的第四种方式:原型链方式
5、继承的第五种方式:混合方式
// 定义一个动物类function Animal (name) { ?// 属性 ?this.name = name || ‘Animal‘; ?// 实例方法 ?this.sleep = function(){ ???console.log(this.name + ‘正在睡觉!‘); ?}}// 原型方法Animal.prototype.eat = function(food) { ?console.log(this.name + ‘正在吃:‘ + food);};function Cat(){ }Cat.prototype = new Animal();Cat.prototype.name = ‘cat‘;// Test Codevar cat = new Cat();console.log(cat.name);console.log(cat.eat(‘fish‘));console.log(cat.sleep());console.log(cat instanceof Animal); //true console.log(cat instanceof Cat); //true
JS继承的实现方式
原文地址:https://www.cnblogs.com/fm060/p/8525713.html