3

What is the convention behind the double at (@@) in method declarations?

For example from: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols

Whenever an object needs to be iterated (such as at the beginning of a for..of loop), its @@iterator method is called with no arguments, and the returned iterator is used to obtain the values to be iterated.

html_programmer
  • 18,126
  • 18
  • 85
  • 158
  • I imagine it's because...it's extremely unlikely for somebody to already have `@@` so it makes it look "special". – VLAZ Nov 19 '16 at 12:17

1 Answers1

8

That's a specification shorthand for "well-known symbols," rather than something you'd type literally. For instance, @@iterator is Symbol.iterator, which is the key you'd use to get the default iterator for an object:

let defaultIterator = theObject[Symbol.iterator];
T.J. Crowder
  • 1,031,962
  • 187
  • 1,923
  • 1,875