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)