【发布时间】:2015-12-07 14:04:08
【问题描述】:
我正在玩 JavaScript/ES6 中的新东西。我的代码中有一个Uncaught ReferenceError: this is not defined(...) player.js:5。据我所知,这里没有错误!这是一个错误吗?有什么解决方法吗?
index.html
<html>
<head>
<script type="text/javascript" src="js/entity.js"></script>
<script type="text/javascript" src="js/player.js"></script>
<link href="css/style.css" rel="stylesheet" type="text/css">
<title>Test</title>
</head>
<body>
<canvas id="screen" width=500 height=500></canvas>
<script type="text/javascript">initialize();</script>
</body>
</html>
entity.js
"use strict";
class Entity {
constructor() {
console.log("Entity");
}
}
player.js
"use strict";
class Player extends Entity {
constructor() {
console.log("Created"); // <- error here
}
}
【问题讨论】:
-
是我遗漏了什么,还是你从来没有在任何地方声明
initialize??? -
这是我错误留下的旧且不相关的代码。