// // 一
// function Father(uname, age) {
// this.uname = uname;
// this.age = age;
// }
// Father.prototype.money = function() {
// console.log(100000);
// };
// // 二
// class Father {
// constructor(uname, age) {
// this.uname = uname;
// this.age = age;
// }
// money() {
// console.log(100000);
// };
// }
// // 一和二是一个意思
// ES6 之前通过 构造函数 + 原型 实现面向对象 编程
// (1) 构造函数有原型对象 prototype
// (2) 构造函数原型对象 prototype 里面有constructor 指向构造函数本身
// (3) 构造函数可以通过原型对象添加方法
// (4) 构造函数创建的实例对象有__proto__原型指向 构造函数的原型对象
// ES6 通过 类 实现面向对象编程
class Star {
}
console.log(typeof Star); //打印的是一个函数
// 1. 类的本质其实还是一个函数 我们也可以简单的认为 类就是构造函数的另一种写法
// (1) 类有原型对象 prototype
console.log(Star.prototype);
// (2) 类原型对象 prototype 里面有constructor 指向类本身
console.log(Star.prototype.constructor);
// (3) 类可以通过原型对象添加方法
Star.prototype.sing = function() {
console.log('我会唱歌');
}
var ldh = new Star();
// console.log(ldh);
console.dir(ldh);
// (4) 类创建的实例对象有__proto__原型指向 类的原型对象
console.log(ldh.__proto__ === Star.prototype);