Array.프로필 [@iterator] ← 이거 @@은 뭐예요?

2580 단어 JavaScripttech
MDN에는 간혹 두 개의 위 첨자@@의 기재법이 나타난다.

Array.prototype[@@iterator]()


The @@iterator method is part of The iterable protocol, that defines how to synchronously iterate over a sequence of values.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/@@iterator
그러나 이 메모를 JavaScript 또는 TypeScript의 처리 시스템에 직접 입력하면 구문 오류가 발생할 수 있습니다.
console.log(Array.prototype[@@iterator]());
// => Uncaught SyntaxError: Invalid or unexpected token
그럼 이거@@는 어디서 났는지, 무엇을 의미하는 기법일까.

결론


이것은 문서에 사용된 well-known symbols의 줄임말로 ECMAScript의 규격에 정의되어 있습니다.
Within this specification a well-known symbol is referred to by using a notation of the form @@name, where "name"is one of the values listed in Table 1.
https://www.ecma-international.org/ecma-262/#sec-well-known-symbols
다만 "규격 내에서 빈번하게 참조되기 때문에 간략 기법을 쉽게 도입했다"며 자바스크립트라는 프로그래밍 언어의 행동과는 상관이 없지만, 편리하기 때문에 MDN 등 다른 파일에서도 활용됐다.@@Symbol.로 바꾸면 아마 이동하는 코드라고 볼 수 있을 거예요.
console.log(Array.prototype[Symbol.iterator]());
// => Array Iterator {}

좋은 웹페이지 즐겨찾기