Years ago I heard that extending system objects like "Element" or "Math" was "bad". Whilst I knew that legacy IE (of which I'm out of ***'s to give, my ***'s have run all dry) didn't do proper inheritance to live DOM Elements, in modern browsers what reasons are there for extending Array, String, Element, Object, Node, etc, etc being a "bad thing" you "shouldn't do".
The only one I know of is namespace collisions, and even in that case you could simply use uniform prefixes -- like a double underscore -- to mark them as "proprietary".
For example, what's wrong with:
Node.prototype.__flush = function() {
while (this.firstChild) this.removeChild(this.firstChild);
};
That would make it a "forbidden" technique just because it is being applied to Node?
Or...
Object.defineProperty(
String.prototype,
'__htmlSpecialChars',
{
get : function() {
return this.replace(/[&<>"']/g, function(m) {
return '&#38;#' + m.charCodeAt() + ';';
});
}
}
);
The reason I'm asking is my original version of elementals was going to work this way, and I'm thinking on dragging Elementals 4 back to this, since IMHO:
var myString = 'This is a <test>';
console.log(myString.__htmlSpecialChars);
Would be vastly superior to:
var myString = 'This is a <test>';
console.log(_.htmlSpecialChars(myString));
// where _ is my elementals core object
Probably faster executing too. I know I was told legitimate reasons not to use this approach a decade ago, but damned if I can remember what they were. Was it literally just "IE7/earlier can't do that" and that's it?!?
Trying to challenge my own assumptions here; assumptions that may have been based on misinformation, misunderstanding, or that flat out simply no longer apply years later.