完美清晰掌握ES5构造函数实现类的继承
ES5中的类 es5中的类 function Person ( ) { this . name = '张三' ; this . age = 12 ; } var p = new Person ( ) ; console . log ( p . name ) 构造函数和原型链里面增加方法 function Person ( ) { this . name = '李四' ; this . age = 23 ; this . run = function ( ) { console . log ( ` ${ this . name } 运动了~` ) // console.log(this) } } // 在原型链上扩展属性和方法(原型链上的属性会被多个实例共享,构造函数不会) Person . prototype . sex = '男' ; Person . prototype . work = function ( ) { console . log ( `性别: ${ this . sex } ` ) } var p = new Person ( ) ; p . run ( ) ; p . work ( ) 类的静态方法 function Person ( ) { } Person . love = function ( ) { console . log ( '我是类的静态方法