Why is it bad to write such a code?
Element.prototype.hide = function () { this.hidden = true };
Element.prototype.show = function () { this.hidden = false };
Why is it bad to write such a code?
Element.prototype.hide = function () { this.hidden = true };
Element.prototype.show = function () { this.hidden = false };
You mean to change native JS prototypes(like String
) or in general?
Changing native prototypes can be problematic since you can never know if there is another library, which does the same but gives e.g. slightly different results.
Changing prototypes of your objects / third-party libraries is perfectly fine because this is how polymorphism in JS can be achieved.