Benjamin (Inglor) Gruenbaum (2013-10-13T07:54:12.000Z)
domenic at domenicdenicola.com (2013-10-28T14:56:35.968Z)
Scoped binding of a method to an object Well, I know how some languages solve this issue but I wondered if ECMAScript considered addressing this or already have and I missed it. Often, I want to extend objects, for example - Array.prototype.shuffle - takes an array and shuffles it. However, this is considered bad practice for many reasons I don't have to repeat here (what if other libraries also override it? What if some user code? What if it makes it to the standard some day?) The problem is even more prevalent in stuff like String.prototype.contains which we know will be in the next spec - people had little way to add that function to the string prototype *before* it was adapted to the spec and not get eventually bitten. Stuff like underscore _.shuffle makes for less object oriented code, I find it harder to write and it feels like the code is not where it belongs. What I'd like is a way to add such methods in a scoped way, so within *my* code I get to use .shuffle but any code that is not in that scoped block does not get access to this method. Has there been a proposal or discussion about this in the past?