Hacker News new | ask | show | jobs
by heydenberk 4245 days ago
Spread is like python's *args.

Instead of this:

  var mapArgs = function() {
    var args = Array.prototype.slice.call(arguments, 0, arguments.length - 1);
    var mapper = Array.prototype.slice.call(arguments, arguments.length - 1);
    return args.map(mapper);
  };
You can do this:

  var mapArgs = function(...args, mapper) {
    return args.map(mapper);
  };
And you can also use it to apply. Instead of:

  var max = Math.max.apply(null, [1, 2, 3, 4]);
You can do:

  var max = Math.max(...[1, 2, 3, 4]);