4 ms·
Symbols don't have any interesting properties to access. The problem is this case: s[t + ""] vs s[t] For all types they are the same because as we know in
by hdhzy 9y ago
Symbols don't have any interesting properties to access.
The problem is this case:
s[t + ""] vs s[t]
For all types they are the same because as we know in JS all properties (even array indexes) are converted to strings. But not for symbols, if you use symbol as "t" then implicitly calling toString would give you wrong result in first case. As this is clearly different from the rest of JS objects it's better to throw an error rather that silently proceed.
> I though that primatives would be unboxed so that their toString method could be called. Apparently not.
It's the other way around. Primitives do not have any properties so to call a method on it they are boxed before call.
An example:
Number.prototype.getBoxed = function () { return this}
var x = 2..getBoxed()
X will be a Number wrapper object, not a primitive.