/* 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()
网友评论