@@iterator in arguments object

Jason Orendorff jason.orendorff at gmail.com
Sun Dec 23 17:46:09 PST 2012


On Sun, Dec 23, 2012 at 1:26 PM, Wes Garland <wes at page.ca> wrote:

> Arguments object is used here to fill the rest void, but also as an
> argument to apply (after converting into a real array) when writing wrapper
> functions; eg monkey patches, userspace profiling, etc.
>
> Is there an ES6 way to use apply on rest params? If not, arguments must
> live on.
>

There is something really nice. You can use the ... operator when calling a
function. For example, if you're wrapping a function foo:

  _origFoo = foo;
  foo = function (a, b, ...rest) {
      // ... do something ...
      return _origFoo(a, b, ...rest);
  };

If you're wrapping a method it's not quite as nice, but:

  _origMethod = Bar.prototype.method;
  Bar.prototype.method = function (a, b, ...rest) {
      // ... do something ...
      return _origMethod.call(this, a, b, ...rest);
  };

-j
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20121223/27771577/attachment.html>


More information about the es-discuss mailing list