Array.프로필 [@iterator] ← 이거 @@은 뭐예요?
2580 단어 JavaScripttech
@@
의 기재법이 나타난다.Array.prototype[@@iterator]()
The
@@iterator
method is part of The iterable protocol, that defines how to synchronously iterate over a sequence of values.그러나 이 메모를 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.
다만 "규격 내에서 빈번하게 참조되기 때문에 간략 기법을 쉽게 도입했다"며 자바스크립트라는 프로그래밍 언어의 행동과는 상관이 없지만, 편리하기 때문에 MDN 등 다른 파일에서도 활용됐다.
@@
를 Symbol.
로 바꾸면 아마 이동하는 코드라고 볼 수 있을 거예요.console.log(Array.prototype[Symbol.iterator]());
// => Array Iterator {}
Reference
이 문제에 관하여(Array.프로필 [@iterator] ← 이거 @@은 뭐예요?), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://zenn.dev/qnighy/articles/fadb75c954d2d2텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)