class Demo {
constructor(name, unitPrice, number) {
this.name = name
this.unitPrice = unitPrice
this.number = number
Demo.count++
}
static count = 0
get totalPrice() {
return Demo.count * this.number
}
increase() {
this.number++
}
}
var Demo1 = (() => {
'use strick'
function Demo(name, unitPrice, number) {
if (Object.getPrototypeOf(this) !== Demo.prototype) {
throw new Error('new')
}
this.name = name
this.unitPrice = unitPrice
this.number = number
Demo.count++
Object.defineProperty(this, 'totalPrice', {
get() {
return this.number * Demo.count
},
enumerable: false
})
}
Demo.count = 0
Object.defineProperty(Demo, 'increase', {
value() {
if (Object.getPrototypeOf(this) === Demo.prototype.increase.prototype) {
throw new Error('ddddd')
}
return this.number++
},
enumerable: false
})
return Demo
})()
Object.defineProperty(Demo.prototype, 'totalPrice', {
get() {
return this.number * Demo.count
},
enumerable: false
})
var d = new Demo1(1, 2, 3)
console.log(d.totalPrice, 'd.totalPrice')
console.log(d, '<-----d')
console