Reputation: 704
In Chrome on Windows, I have this in the console:
> Symbol.iterator
< Symbol(Symbol.iterator)
> Symbol.iterator = "Hello!";
< "Hello!"
> Symbol.iterator;
< Symbol(Symbol.iterator)
So Symbol.iterator (thankfully) doesn't change, but why doesn't my attempt to assign to it throw an error?
Upvotes: 1
Views: 63
Reputation: 665410
In sloppy mode, the failed assignment doesn't cause an exception. Use strict mode instead:
(function(){ "use strict"; Symbol.iterator = "Hello" }())
Uncaught TypeError: Cannot assign to read only property
iterator
of functionfunction Symbol() { [native code] }
Upvotes: 2