美文网首页
面向对象es5 es6对比-基本型

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

作者: Yokiijay | 来源:发表于2019-04-25 10:42 被阅读0次
/* 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()

相关文章

网友评论

      本文标题:面向对象es5 es6对比-基本型

      本文链接:https://www.haomeiwen.com/subject/udjagqtx.html