I was just looking at #1314, where a user accidentally overrwrote p5's text function, and realized that one potential way to prevent this from happening is by defining p5's methods (in global mode) to be non-writable properties of the window object. Here's an example:
Object.defineProperty(window, 'text', {
value: function() {
console.log("TEXT WAS CALLED");
},
writable: false
});
text += "blah";
text();
In the above example, the assignment to text will silently fail, and the subsequent calling of text() will succeed.
Two alternatives that I think are possible:
- Throw a helpful error if the value is overwritten, instead of failing silently.
- Permit overwriting the value, but log a helpful warning telling the user that they just overwrote a core p5 method.
I guess alternative (2) might be best if we don't want to break backwards compatibility... Or we can just leave the current behavior as-is, of course.
I was just looking at #1314, where a user accidentally overrwrote p5's
textfunction, and realized that one potential way to prevent this from happening is by defining p5's methods (in global mode) to be non-writable properties of thewindowobject. Here's an example:In the above example, the assignment to
textwill silently fail, and the subsequent calling oftext()will succeed.Two alternatives that I think are possible:
I guess alternative (2) might be best if we don't want to break backwards compatibility... Or we can just leave the current behavior as-is, of course.