JavaScript/ES6で新しいものを試しています。私はUncaught ReferenceError: this is not defined(...) player.js:5
を私のコードに入れます。私が見る限り、ここにはエラーはありません!これはバグですか?回避策はありますか?クラスコンストラクタで "Uncaught ReferenceError:これは定義されていません"
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クラスはスーパーなしで拡張可能]の重複の可能性があります(http://stackoverflow.com/questions/31067368/javascript-es6-class-extend-without-super) – Makyen