Using ...rest parameters

60 views
Skip to first unread message

--Hyde

unread,
Feb 1, 2020, 5:05:41 AM2/1/20
to google-apps-sc...@googlegroups.com
I have been using the destructuring assignment syntax in Google Apps Script for some time. It simplifies code like this quite a bit:

  var [needle, haystack, startAt] = validateArguments_({ args: arguments, minNumArgs: 2 });

The spread syntax, the ...obj spread operator and rest parameters would obviously be very useful as well, but I have been unable to get them to work. This is a bit confusing, since Google's own sample code does use the spread operator, for example in the Date Add and Subtract add-on sample code:

  if (max == 0) {
    return func(...args);
  }

Google originally used func.apply(null, args) in the 15 December 2017 commit of the code, but switched to func(...args) in the 20 June 2018 commit.

Is this a V8 only thing, or is there a way to use the spread syntax and rest parameters in regular Rhino Google Apps Script?

Or did someone at Google just blindly "fix" a lint warning in the Date Add and Subtract add-on and commit sample code that does not actually work in Google Apps Script?

Cheers --Hyde

AD:AM

unread,
Feb 5, 2020, 11:03:44 PM2/5/20
to Google Apps Script Community
--Hyde, just letting you know I pulled some strings and got the spread operator working for you. ;-)

Thanks for the tip about the destructuring assignment syntax though - I actually had no idea it worked in "Rhino" GAS.

Cheers
Adam

--Hyde

unread,
Feb 6, 2020, 3:15:27 AM2/6/20
to Google Apps Script Community
Hi Adam,

Really appreciate you going into all that trouble just to get those three magic dots work for me! I will let you know the next time I need some new or not-yet-invented syntax to work.

Cheers --Hyde

Reply all
Reply to author
Forward
0 new messages