![原型链小记录](https://img-blog.csdn.net/20180321095003190?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvcGludHUyNzQxMTE0NTE=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast)
// 父类
var Person = function (name, age) {
// 判断执行过程中this是否当前对象(如果是,说明是用new创建的)
if (this instanceof Person) {
this.name = name;
this.age = age;
// 否则重新创建这个对象
} else {
return new Person(title, time);
}
}
Person.prototype.getName = function () {
return this.name;
}
// 子类
var Man = function (name, age) {
Person.call(this, name, age);
}
Man.prototype = Object.create(Person.prototype);
Man.prototype.constructor = Man;
var bob = new Man('bob', 18);
console.log(bob);
console.log(bob.__proto__);
console.log(Man.prototype);
// bob.__proto__ 指向父级的 prototype
console.log(bob.__proto__ === Man.prototype);
console.log(Man.prototype.constructor);