此代码块发出一个事件并通过一个整数:
function executeEvent() {
// here you could use the event bus to chuck the pfio event to the pfio event api.....
if (eventQueue.length > 0) {
for (var i = 0; i < eventQueue.length; i++) {
var event = eventQueue[i];
if (event.processing){
console.log(colors.yellow("Already processing event"));
continue;
}
else
event.processing = true;
eventBus.emit('event.process', i);
}
}
setImmediate(executeEvent.bind(this));
};但是,当它接收到事件时:
eventBus.on('event.process', processEvent);
function processEvent(index) {
console.log("Processing %s %d", colors.yellow("Event"), colors.red(index.toString()));
var event = getEvent(index);
var current = new Date().getTime(); // get the number of milliseconds from 1/1/1970
var fireEvent = false;
if (event.eventType == 2) // timer or interval respectively
fireEvent = current - event.init.getTime() >= event.when;
if (event.eventType == 3) // schedule
fireEvent = current >= event.when;
if (fireEvent)
eventBus.emit('event.fire', event);
else
event.processing = false;
}
function getEvent(index){
return eventQueue[index];
}index是NaN。有人能告诉我错误在哪里吗?我猜它可能在事件总线的on事件中。
发布于 2014-04-03 13:34:34
变化
console.log("Processing %s %d", colors.yellow("Event"), colors.red(index.toString()));至
console.log("Processing %s %s", colors.yellow("Event"), colors.red(index.toString()));尽管index在输入函数时是整数,但colors.red(index.toString())的返回值不再是整数,%d替换字符串将尝试将类型转换为整数,从而导致NaN。
https://stackoverflow.com/questions/22838514
复制相似问题