1.混入式继承
var obj1 = {} var obj2 = { name: ‘ys‘, age: 18 } for(var k in obj2){ obj1[k] = obj2[k] }
2.原型继承
// 方法一: function Person() { }; var obj1 = {} var obj2 = { name: ‘ys‘, age:18 } obj2 = new Person Person.prototype = obj2 // 方法二: function Person() { }; var obj1 = {} var obj2 = { name: ‘ys‘, age:18 }
for(var k in obj2){
Person.prototype[k] = obj2[k]
}
3.经典继承
var obj1 = {} var obj2 = { name: ‘ys‘, age: 19 } obj1 = Object.create(obj2)
4.es6 class extends继承
var obj1 = {} var obj2 = { name: ‘ys‘, age: 19 } class obj1 extends obj2 { // 让obj1继承了obj2的属性和方法 }