Javascript匿名函数在同一数组上重新映射两次这两个映射都有效还是替换了旧的映射?
我将这个JavaScript转换成Java,它看起来工作得很好,但是仍然存在一些小故障,我正在尝试修复它们,到目前为止,这是我认为存在的问题之一 JavaScript匿名函数在同一数组上重新映射两次这两个映射都有效还是替换了旧的映射?如果它被替换了,为什么这里会有这种情况?我99%确定它会被替换为下一个函数,因为它可能是Javascript匿名函数在同一数组上重新映射两次这两个映射都有效还是替换了旧的映射?,javascript,arrays,anonymous-function,remap,Javascript,Arrays,Anonymous Function,Remap,我将这个JavaScript转换成Java,它看起来工作得很好,但是仍然存在一些小故障,我正在尝试修复它们,到目前为止,这是我认为存在的问题之一 JavaScript匿名函数在同一数组上重新映射两次这两个映射都有效还是替换了旧的映射?如果它被替换了,为什么这里会有这种情况?我99%确定它会被替换为下一个函数,因为它可能是cGBC或不是cGBC这行this应该没有理由。memoryHighWriter[0x2]=this.memoryHighWriteNormal应该有效,但我不确定 据我所知,m
cGBC
或不是cGBC
这行this应该没有理由。memoryHighWriter[0x2]=this.memoryHighWriteNormal
应该有效,但我不确定
据我所知,memoryWriteJumpCompile
函数也会初始化从0
到0xFFFF
的所有地址,如果每个地址在以后没有使用,它仍然会得到一个默认操作
但是为什么还要为this.memoryHighWriter[0x2]=this.memoryHighWriteNormal提供默认操作呢代码>如果它在下一个函数中仍然被替换
this.registerWriteJumpCompile(); //Compile the I/O write functions separately...
完整的源代码位于:
下面的调用是在memoryWriteJumpCompile
函数中调用的
this.registerWriteJumpCompile(); //Compile the I/O write functions separately...
recompileModelSpecificIOWriteHandling()在寄存器writejumpcompile
完成后立即调用code>
GameBoyCore.prototype.recompileModelSpecificIOWriteHandling = function () {
if (this.cGBC) {
//GameBoy Color Specific I/O:
//SC (Serial Transfer Control Register)
this.memoryHighWriter[0x2] = this.memoryWriter[0xFF02] = function (parentObj, address, data) {
if (((data & 0x1) == 0x1)) {
//Internal clock:
parentObj.memory[0xFF02] = (data & 0x7F);
parentObj.serialTimer = ((data & 0x2) == 0) ? 4096 : 128; //Set the Serial IRQ counter.
parentObj.serialShiftTimer = parentObj.serialShiftTimerAllocated = ((data & 0x2) == 0) ? 512 : 16; //Set the transfer data shift counter.
} else {
//External clock:
parentObj.memory[0xFF02] = data;
parentObj.serialShiftTimer = parentObj.serialShiftTimerAllocated = parentObj.serialTimer = 0; //Zero the timers, since we're emulating as if nothing is connected.
}
}
...
} else {
...
//Fill in the GameBoy Color I/O registers as normal RAM for GameBoy compatibility:
//SC (Serial Transfer Control Register)
this.memoryHighWriter[0x2] = this.memoryWriter[0xFF02] = function (parentObj, address, data) {
if (((data & 0x1) == 0x1)) {
//Internal clock:
parentObj.memory[0xFF02] = (data & 0x7F);
parentObj.serialTimer = 4096; //Set the Serial IRQ counter.
parentObj.serialShiftTimer = parentObj.serialShiftTimerAllocated = 512; //Set the transfer data shift counter.
} else {
//External clock:
parentObj.memory[0xFF02] = data;
parentObj.serialShiftTimer = parentObj.serialShiftTimerAllocated = parentObj.serialTimer = 0; //Zero the timers, since we're emulating as if nothing is connected.
}
}
}
它只是一个普通的数组元素。重新指定时,它将替换旧值。它没有什么特别之处,只是因为你把函数放进去了。我也是这么想的,但我开始怀疑它可能会在同一个索引上创建两个数组元素,这两个数组元素同时执行javascript有时是不可预测的。我猜这只是作者忘记删除的旧代码。Javascript并不是那样不可预测的。它的数组与大多数语言中的数组几乎相同。