相关疑难解决方法(0)

在类构造函数中"未捕获的ReferenceError:未定义"

我正在玩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>
Run Code Online (Sandbox Code Playgroud)

entity.js

"use strict";

class Entity {
    constructor() {
        console.log("Entity");
    }
}
Run Code Online (Sandbox Code Playgroud)

player.js

"use strict";

class Player extends Entity {
    constructor() {
        console.log("Created"); // <- error here
    }
}
Run Code Online (Sandbox Code Playgroud)

javascript ecmascript-6

42
推荐指数
1
解决办法
2万
查看次数

标签 统计

ecmascript-6 ×1

javascript ×1