36
我正在玩JavaScript/ES6中的新東西。我的代碼中有一個Uncaught ReferenceError: this is not defined(...) player.js:5
。據我所知,這裏沒有錯誤!這是一個錯誤?任何解決方法?「Uncaught ReferenceError:this is not defined」in class constructor
的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'任何地方? – Bergi
這是舊的和不相干的代碼,留在我的錯誤。 – bshaw
可能的重複[Javascript ES6 class extend without super](http://stackoverflow.com/questions/31067368/javascript-es6-class-extend-without-super) – Makyen