This specific snippet of code fails to accurately identify polyfilled Symbol.toStringTag
. Although it is feasible to polyfill Symbol
and its impact on toString
(as demonstrated by core-js
), introducing a new primitive type for typeof
is not possible. The current implementation does not verify that Symbol
is also a function, nor does it require creating a new symbol.
A revised version should look something like this:
if (typeof Symbol !== "undefined" && Symbol && Symbol.toStringTag) {
var obj = {};
obj[Symbol.toStringTag] = "Test";
return toString.call(obj) == "[object Test]";
}
Polyfilling Symbol
and its influence on toString
can be easily achieved. If a developer is seeking specific JS functionalities in their application, they may want to prioritize those that cannot be polyfilled, particularly in older browsers. This could involve using Object.setPrototypeOf
for ES5, leveraging Proxy
in ES6, or identifying syntactic features.