1 回答

TA貢獻1911條經驗 獲得超7個贊
看到您的導出,您似乎正在導出一個arrow function,不幸的是,我們不能使用箭頭函數進行constructor調用(即我們不能new與它們一起使用),因為它們沒有[[Construct]]方法。因此,prototype箭頭函數也不存在該屬性。
所以只需將箭頭功能更改為正常功能即可。
var Clock = function(options) {
var timer, offset, clock, interval
options = options || {}
options.delay = options.delay || 1000
reset()
function start() {
if (!interval) {
offset = Date.now()
interval = setInterval(update, options.delay)
}
}
function update() {
clock += delta()
}
function delta() {
var now = Date.now(),
d = now - offset;
offset = now;
return d;
}
function stop() {
if (interval) {
clearInterval(interval)
interval = null
}
}
function reset() {
clock = 0
}
function read() {
return clock
}
this.start = start
this.stop = stop
this.reset = reset
this.read = read
}
module.exports = Clock;
添加回答
舉報