in Education by
Trying to use ES6 but I'm stuck on something. To make it simple there is two problems : JS source code is not executed within a script called with module="type" HTMLelements importing directly from index.html returns SyntaxError: fields are not currently supported Tried and dug both cases, can't get what is wrong. Paths are right. Not putting .js extension within from statement was returning errors for the second try with import used directly in index.html. Previously initGame() was a $(document).ready(function(e) { ... });. Also returns an error, if I don't sepcify type="module" within index.html. <!DOCTYPE html>
import { initGame } from "./lib/js/core.js"; initGame(); //core.js import { Board } from './classes/Board.js'; import { Pawn } from './classes/Pawn.js'; export function initGame () { console.log("plop"); var $displayer = $('#displayer'); var board = new Board($displayer, 32, 19, 19, ['#ffffcc', '#333333']); console.debug(board); } //Board.js import { TileMap } from "./TileMap.js" export class Board extends TileMap { _tileColors; constructor(wrapper, tileSize, columnsNb, rowsNb, tileColors) { super(wrapper, tileSize, columnsNb, rowsNb); this._name = "Board:" + columnsNb + ":" + rowsNb; this.selector.css({ class: "board" }) tileColors.forEach(function(color, i) { this._tileColors[i] = color; }); this.colorize(); } colorize() { this._grid.forEach(function(col, i) { col.forEach( function(tile, j) { tile.color = ((i + j) % 2 === 0) ? this.getColor(0) : this.getColor(1); }); }); } getColor(index) { return this._tileColors[index]; } } Just wanting to use the modulare system of ES6 for convenience and self teaching. Errors: If no type="module" src="path" specified: SyntaxError: import declarations may only appear at top level of a module empty console if just and $(document).ready() variation for core.js If this version is active: SyntaxError: fields are not currently supported JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
The syntax you used to declare _tileColors is called a field declaration and is a highly experimental proposal. They were only implemented in Chrome 72 and above, and seem to be partially implemented in some Firefox builds if you enable the experimental flag for them. You need to remove the line _titleColors; from the class and to set this._titleColors within the constructor. Besides, your constructor's code as it stands is broken, it's trying to set the content of _titleColors but the variable isn't even initialized. Instead, you can do (assuming titleColors is an array): // create an array copy of titleColors this._tileColors = [...titleColors];

Related questions

0 votes
    Suppose that while writing the R code that consists of multiple functions. While executing the code, there is an error ... you use to find the function that is facing problem?...
asked Oct 16, 2020 in Technology by JackTerrance
0 votes
    In the context of a complex application, I need to import user-supplied 'scripts'. Ideally, a script ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 9, 2022 in Education by JackTerrance
0 votes
    In the context of a complex application, I need to import user-supplied 'scripts'. Ideally, a script ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 5, 2022 in Education by JackTerrance
0 votes
    When does JavaScript code appear inline within an HTML file? (a) Between the script tag (b) ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Oct 23, 2021 in Education by JackTerrance
0 votes
0 votes
    Which is a wrapped Java array, accessed from within JavaScript code? (a) JavaArray (b) JavaClass (c) ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Oct 21, 2021 in Education by JackTerrance
0 votes
    Predict the output of the following JavaScript code.
    Predict the output of the following JavaScript code. var a="blogsforblog"; var x=a.lastIndexOf("b"); document.write(x); A) 8 B) 0 C) 9 D) Error...
asked Feb 27, 2021 in Technology by JackTerrance
0 votes
    Predict the output of the following JavaScript code. a = 8 + "8"; document.write(a); A) 16 B) Compilation Error C) 88 D) Run Time Error...
asked Feb 27, 2021 in Technology by JackTerrance
0 votes
    What is the HTML tag under which one can write the JavaScript code? A) B) C)
    What is the best Azure solution for executing the code without a server?...
asked Jul 31, 2021 by JackTerrance
...