It is the predominant opinion that built-in Javascript prototypes should not be extended (or altered in any way):
Array.prototype.empty = function () { return this.length === 0; } // don't try that
Does this rule also apply to ES2015 symbols?
const empty = Symbol("empty");
Array.prototype[empty] = function empty() { return this.length === 0; }
Since symbol
is a mix of string
(primitive, immutable) and object
(identity) there can be no object property naming conflicts by definition.
Normal object reflection is not affected by symbols:
Object.getOwnPropertyNames(Array.prototype).indexOf("empty"); // -1
But ES2015 reflection with Reflect.ownKeys(Array.prototype)
is.
So this question is mainly about how we'll use Reflect.ownKeys
and Object.getOwnPropertySymbols
in the future.