面向对象es5 es6对比-基本型

2019-04-25  本文已影响0人  Yokiijay
/* A */
class A {
  constructor(options){
    this.msg = options.msg
  }
  log(){
    console.log( this.msg )
  }
}

const a = new A({
  msg: 'hello'
})

a.log()

/* B */
function B(options){
  this._init(options)
}

B.prototype = {
  _init: function(options){
    this.msg = options.msg
  },
  log: function(){
    console.log( this.msg )
  }
}

const b = new B({
  msg: 'wow'
})

b.log()
上一篇 下一篇

猜你喜欢

热点阅读