简体   繁体   English

未捕获的语法错误:意外的严格模式保留字

[英]Uncaught SyntaxError: Unexpected strict mode reserved word

I have been searching for a while now on what this error means (error: Uncaught SyntaxError: Unexpected strict mode reserved word), or how to fix it but I just cannot find anything, so I was hoping that someone here could help?我一直在搜索这个错误的含义(错误:未捕获的语法错误:意外的严格模式保留字),或者如何修复它,但我找不到任何东西,所以我希望这里有人可以提供帮助? By the way going to bed on this so only gonna read responses (if any) tomorrow.顺便说一下,明天就去睡觉,所以只阅读回复(如果有的话)。

Here is the line giving me the error:这是给我错误的行:

for (let i = 0; i < 10; i++) { //(And then the code)

FOR PEOPLE WHO NEED CONTEXT:对于需要上下文的人:

const canvas = document.getElementById('canvas1');

const ctx = canvas.getContext('2d');

class background {
  draw(){   
    ctx.fillstyle = 'green';
    ctx.beginPath();
    ctx.fillRect(0,10,800,500);
    ctx.fill();
    ctx.closePath;
  };
};

const Backdrop = new background();

Backdrop.draw();

class artist {
  for (let i = 0; i < 10; i++) {
    draw(){
      ctx.fillStyle = 'lime';
      ctx.beginPath();
      ctx.fillRect(0+i,10,20,15);
      ctx.fill();
      ctx.closePath;
    };
  };
};

const box = new artist();

box.draw();

Ok send help, thanks!!好的发送帮助,谢谢!!

As @Barmar commented you can use the for loop inside your draw() .正如@Barmar 所评论的,您可以在draw()使用 for 循环。

Here is a working example:这是一个工作示例:

 const canvas = document.getElementById('c') canvas.style.background = 'black' const ctx = canvas.getContext('2d') class artist { draw() { ctx.fillStyle = 'lime' for (let i = 0; i < 10; i++) { ctx.fillRect(10 + i * 30, 30, 20, 15) } } } const box = new artist() box.draw()
 <canvas width="400px" height="170px" id="c"></canvas>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM