Reputation: 303
Do objects use the property Symbol.iterator
, instead of just iterator
, to prevent us from overwriting the iterator
property on the Object prototype?
If so, are there any other reasons?
Just trying to understand symbols in JS.
Upvotes: 0
Views: 51
Reputation: 2941
If it were just iterator
, it could break old code that had objects with methods called iterator
. Likewise, whenever the designers of JS want to let developers add other special methods to their objects, they would run the risk of clobbering existing names and breaking existing code.
An alternative is Python’s __double_underscore__
convention where developers are not supposed to defined methods named like this.
Upvotes: 3