What Every JavaScript Developer Should Know About ECMAScript 2015 (OdeToCode Programming Series) by K. Scott Allen

What Every JavaScript Developer Should Know About ECMAScript 2015 (OdeToCode Programming Series) by K. Scott Allen

Author:K. Scott Allen [Allen, K. Scott]
Language: eng
Format: epub
Publisher: OdeToCode LLC
Published: 2015-11-20T18:30:00+00:00


expect(Object.getOwnPropertySymbols(person)).toEqual([firstName]);

let symbol0 = Object.getOwnPropertySymbols(person)[0];

expect(person[symbol0]).toBe("Scott");

Now that we know more about symbols, let’s see how symbols relate to iterable objects.

Iterables and Symbols

The ES2015 specification defines several well-known symbols. The JavaScript runtime environment uses well-known symbols in the algorithms described by the specification, and each well-known symbol is a property on theSymbol function itself.

One such well-known symbol isSymbol.iterator. If we can access theSymbol.iterator member of an object, the member should be a method we can use to obtain an iterator. The following code will check to see if strings, arrays, and numbers are iterable by looking for this well-known iterator symbol.



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.