【发布时间】:2019-06-05 22:04:02
【问题描述】:
在我的项目中有一个单色屏幕,您可以写入和清除。在课堂上,我有这两行代码用于清除屏幕。第一个将当前像素值从屏幕推送到堆栈上,以便稍后可以撤消清除屏幕。第二行清除屏幕。问题是撤消堆栈正在获取对 this.pixels 的引用,而不是当时获取它的值。
this.pushUndo(this.pixels); //this.pixels is an array of ints
this.updateScreen(new Array(64*32)); //this.pixels changes at the end of this line but the undo stack shouldn't change its value
【问题讨论】:
-
你可以尝试克隆对象
标签: javascript pass-by-reference pass-by-value