Symbol(Symbol.toStringTag)
indicates that the property is a symbol . Symbols are unique values and you can only reference such a property if you already have a reference to the symbol.
Luckily Symbol.toStringTag
is a well-known symbol , so you can just reference it:
a[Symbol.toStringTag]
Here is an example where you cannot access the property directly:
var obj = (function() {
// prop is a unique value
var prop = Symbol();
return {[prop]: 42};
}());
There is no way to access obj[<the symbol>]
directly since we don't have access to prop
. You can still iterate over the properties though.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.