class 专题
定义 class
//es5 类的定义 属性定义在 function 上, 方法定义在原型链上
function foobar(){
this.foo_ = ‘foo‘;
this.bar_ = ‘bar‘;
}
foobar.prototype.sayHello = function(){ console.log(‘hello‘) }
const fb = new foobar();
fb.sayHello();
// es6 class 语法
class foobar2{
constructor(){
this.foo_ = ‘foo‘;
this.bar_ = ‘bar‘;
}
sayHello(){ console.log(‘hello‘) }
}
const fb2 = new foobar2();
fb2.sayHello();
继承
class father {
sayHi(){ console.log(‘Hi‘) }
}
class son extends father{
constructor () {
super();
this.me=‘son‘
}
sayHello(){ console.log(‘hello‘) }
}
const son1 = new son();
// 调用 father 类的 sayHi 方法时 找自己的原型 son.prototype 是否含有这个 方法
// 通过查看父类的原型判断 是否调用的父类的方法 其中 son.prototype.__proto__=father.prototype
// 通过 hasOwnProperty 判断
son1.sayHi();
异步专题
3. 现代 javascript class 专题 和 异步专题
原文:https://www.cnblogs.com/zonehoo/p/11514683.html