Scoped binding of a method to an object

Rick Waldron waldron.rick at
Sun Oct 13 13:53:01 PDT 2013

On Sun, Oct 13, 2013 at 2:00 PM, Benjamin (Inglor) Gruenbaum <
inglor at> wrote:

> Brendan Eich <brendan at> wrote:
> > No, object detection, polyfilling, and even "prollyfilling" are common
> and successful adaptationsp on the Web.
> Polyfilling is great _after_ the method has already been added to the
> spec. I'm completely fine with adding an shim to IE8,
> the problem with adding a method that's not on the prototype yet is that
> it'll fail in case the spec is different from the implementation I chose.
> If you mentioned PrototypeJS, its `.bind` method is one such example.
> > Your subject recalls a defunct proposal to add lexically-scoped but
> heap-based -- therefore object property-lookup performance hindering --
> extension properties.
> I have to say this surprises me, a performance issue is the last thing I
> expected. What about attaching a prototype as a closure variable, something
> (and this is a syntax I __don't__ like) like:
> ```
> (function(use Array){
>     Array.prototype.contains = function() { ...
>     ...
>     // any code here has access to .contains, code that did not originate
> here does not have such access, much like a closure.
>     // other code is free to use Array without any collisions.
> })()
> ```

Another solution is creating your own subclass with custom methods...

class XArray extends Array {
   constructor(...args) {
   contains(arg) { ... }

Then all code in this application uses XArray and gets its custom "contains"

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the es-discuss mailing list