ES6 spread operator + Date constructor = awesome
Published May 31, 2014 11:26 am
I've been working with the Date constructor a lot recently and I discovered something. The new spread operator is extremely useful when dealing with the Date constructor.
The long form of the constructor expects two or more of the following parameters: year, month, day, hours, minutes, seconds and milliseconds. If you are creating several `Date` objects representing the same date, perhaps at different times during that day it is really handy to create an array of the common parameters and then insert them into a Date constructor with the spread operator:
var may31 = [2014, 4, 31],
midnight = new Date (...may31),
noon = new Date(...may31, 12),
five30 = new Date(...may31, 5, 30);