SOURCE

console 命令行工具 X clear

                    
>
console
// https://www.cnblogs.com/zjunet/p/4559895.html
// 函数 function
function person(name) {
    console.log(name);
}

person('js');

// 构造函数
// 和函数的直观区别,变量名大写了
function Person(name) {
    this.name = name;
    this.showMe = function () {
        console.log(this.name);
    }
}
Person.prototype.from = function () {
    console.log('来自prototype');
}

var doudou = new Person('doudou');	// 看见new操作符,Person称之为类
// 但是没有关键字Class,em...那把Person叫做构造函数好啦~
doudou.showMe();


console.log(`doudou.prototype: ${doudou.prototype}`);	// 使用new操作符生成的对象没有prototype属性
console.log(typeof Person.prototype);	// 构造函数的prototype是一个对象
console.log(Person.prototype.constructor === Person); // 构造函数的prototype的constructor是构造函数本身

doudou.from();	// '来自prototype'

/*
《悟透JavaScript》

Q:当我们new了一个对象的时候,发生了什么?	var doudou = new Person('doudou');

A: step1: 建立一个新对象  var doudou = {};
   step2: 将doudou这个对象内置的原型对象设置为构造函数(Person)的prototype属性引用的那个原型对象;(原型继承)
   step3: 将对象doudou作为this参数调用构造函数(Person),完成成员设置等初始化工作。
   
   注: step2中对象内置的原型对象,和prototype不太一样...
*/

// 继承的实现
var father = new Person('father');

console.log(`father.constructor,${father.constructor}`);


function SubPerson () {
    
}
SubPerson.prototype = father;

console.log(SubPerson.prototype.constructor === SubPerson);	// false 
// 目前SuberPerson的原型的构造函数指向的是Person
SubPerson.prototype.constructor = SubPerson;

var son = new SubPerson();
son.showMe();
son.from();

console.log(father.constructor);
console.log(son.constructor);
console.log(SubPerson.prototype.constructor)
<div>
    js
</div>
body{
    background: #ccc;
}