0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Put a semicolon there

Posted at

備忘録です。

.js
'use strict';

let range = {
  from: 1,
  to: 5,

  [Symbol.asyncIterator]() {
    return {
      current: this.from,
      last: this.to,
      async next() {
        await new Promise(resolve => setTimeout(resolve, 1000));
        if (this.current <= this.last)
          return { done: false, value: this.current++ };
        else
          return { done: true };
      }
    };
  }
}; // here

(async () => { for await (const value of range) console.log(value); })();

here のセミコロンを忘れると、 TypeError: {(intermediate value)(intermediate value)(intermediate value)} is not a function というエラーになります。

javascript の行解釈のヤなところorz

参考にしたページ

文法 | JavaScript プログラミング解説

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?