1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
// 父类
function Parent() {
this.sayHello = function () {
console.log("Hello");
}
}

Parent.prototype.a = "我是父类prototype上的属性";
// 子类
function Child() {
Parent.call(this)
}

// 创建两个Child实例
var child1 = new Child();
var child2 = new Child();

console.log(child1.sayHello === child2.sayHello);// false

var parentObj = new Parent();
console.log(parentObj.a);//我是父类prototype上的属性
console.log(child1.a)//undefined

优点:这种继承方式的好处是,原型属性不会被共享。
缺点:它不能继承父类prototype上的属性