У меня проблема с Javascript, я все время получаю неожиданную ошибку маркера «=» при попытке запустить мой скрипт. Я проделал некоторое копание, и способ, объявленный таким образом по умолчанию, является новым для ES6. Я использую «use strict», и именно так я и предполагал использовать самые последние функции Javascript. Но я все еще получаю эту ошибку при попытке использовать параметры по умолчанию, кто-нибудь знает почему? Вот мой код:Неожиданный токен '=' Javascript
// rectangle sprite
"use strict";
// creates canvas
let canvas = document.createElement("canvas");
canvas.setAttribute("width", "500");
canvas.setAttribute("height", "500");
canvas.style.border = "1px dashed black";
document.body.appendChild(canvas);
let ctx = canvas.getContext("2d");
let rectangle = function(
//Define the function's parameters with their default values
width = 32,
height = 32,
fillStyle = "gray",
strokeStyle = "none",
lineWidth = 0,
x = 0,
y = 0
) {
//Create an object called `o` (the lowercase letter "o")
//that is going to be returned by this
//function. Assign the function's arguments to it
let o = {width, height, fillStyle, strokeStyle, lineWidth, x, y};
//Add optional rotation, alpha, visible, and scale properties
o.rotation = 0;
o.alpha = 1;
o.visible = true;
o.scaleX = 1;
o.scaleY = 1;
//Add `vx` and `vy` (velocity) variables that will help us move the sprite
o.vx = 0;
o.vy = 0;
//Add a `render` method that explains how to draw the sprite
o.render = ctx => {
ctx.strokeStyle = o.strokeStyle;
ctx.lineWidth = o.lineWidth;
ctx.fillStyle = o.fillStyle;
ctx.beginPath();
ctx.rect(-o.width/2, -o.height/2, o.width, o.height);
if (o.strokeStyle !== "none") ctx.stroke();
ctx.fill();
};
//Push the sprite object into the `children` array
children.push(o);
//Return the object
return o;
};
любая помощь приветствуется.
Что линия дает эту ошибку? – j08691
Работает для меня на FireFox 44.0.2 –
_ Я использую «use strict», что я и предполагал, это способ использования последних функций Javascript. _ - нет, «использовать строгий», не относящийся к реализации браузера. Функция ES6. – Grundy