我不知道问题出在哪里。
var history = [];
.
.
.
window.onload = function() {
.
.
.
.
history.push({
xCoor: mousex,
yCoor: mousey
});
.
.
.
.
}
完整代码位于:fullCode
这是HTML部分:
<html>
<head>
</head>
<body>
<h3>Canvas Example</h3>
<canvas id="cv" width="600px" height="400px" style="border: 1px solid black"></canvas>
<script src="rendering.js"></script>
<p id="distance">Distance: </p>
</body>
</html>
当我开始绘画时,出现以下错误:
TypeError:history.push不是函数
请帮我。非常感谢你。
最佳答案
我本来是个建议,但是后来我意识到您已经将历史设为全局范围的变量,也许您应该将其称为window.history完全是另外一回事。
var otherHistory = [];
window.onload = function(){
window.otherHistory.push({
xCoor: mousex,
yCoor: mousey
});
}
关于javascript - JavaScript数组推送不是函数,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/34364735/