Syntactic sugar for using a function as if it were a method of its first argument

Andrea Giammarchi andrea.giammarchi at gmail.com
Tue May 27 10:40:20 PDT 2014


( already covered to receive stones )

```javascript

Object.defineProperty(
  Object.prototype,
  'through',
  {
    enumerable: false,
    configurable: true,
    writable: true,
    value: function through(callback) {
      for (var a = [this], i = 1; i < arguments.length; a[i] =
arguments[i++]);
      return callback.apply(null, a);
    }
  }
);

```

so that ..

```javascript

window.HTMLFormElement.prototype.through(Object.getOwnPropertyDescriptor,
'elements').get

document.querySelectorAll('input[type=checkbox][name=
Select_ID]:checked').through(Array.from).map(e => e.value).join(',')

```

Last, but not least, I don't see any concrete advantage/need neither ^_^

Best Regards



On Tue, May 27, 2014 at 10:12 AM, C. Scott Ananian <ecmascript at cscott.net>wrote:

> I like the idea, but I agree that the .{ } syntax isn't quite right.  For
> one thing, on my screen the () are visually very similar to {}, while []
> are easily distinguished.  The leading dot is also a bit odd.  I'd be
> interested in seeing some more alternative syntaxes for this idea.
>   --scott
>
>
> On Tue, May 27, 2014 at 8:54 AM, Claude Pache <claude.pache at gmail.com>wrote:
>
>>
>> Le 27 mai 2014 à 17:04, Jasper St. Pierre <jstpierre at mecheye.net> a
>> écrit :
>>
>> >
>> > (...) Namely, the whole ('elements') looks like a method call
>> containing one argument, rather than having a secret hidden argument as its
>> first.
>> >
>>
>> Yes, it was exactly intended to appear as such, making
>> `obj.{Object.getOwnPropertyDescriptor}('elements')` similar to
>> `obj.hasOwnProperty('elements')`, for instance. If it helps, you could
>> think of `foo.{Bar.baz}` as defining a temporary method:
>> `(function(...args) { return Bar.baz(this, ...args) })`, or:
>> `Bar.baz.bind(Bar, foo)`.
>>
>> —Claude
>>
>> _______________________________________________
>> es-discuss mailing list
>> es-discuss at mozilla.org
>> https://mail.mozilla.org/listinfo/es-discuss
>>
>
>
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20140527/21b109c3/attachment.html>


More information about the es-discuss mailing list