4 ms·
Is it reliable to add methods to a built-in object like CanvasRenderingContext2D? I avoid it, but perhaps just out of superstition.
by tlb 11y ago
Is it reliable to add methods to a built-in object like CanvasRenderingContext2D? I avoid it, but perhaps just out of superstition.
- makepanic 11y agoYou're right, extending the prototype of builtin objects is almost always a bad idea. See String.prototype.contains → String.prototype.includes because mootools extended the String prototype[1] [1] - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/includes#String.prototype.contains https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...
- MJSplot_author 11y agoIf you know what you are doing it's fine, but it might cause incompatibility issues from namespace collisions. You can rearrange the code to accept a context as the first argument if you are worried.