Skip to content

Instantly share code, notes, and snippets.

@marcomorain
Last active December 28, 2015 00:19
Show Gist options
  • Select an option

  • Save marcomorain/7413064 to your computer and use it in GitHub Desktop.

Select an option

Save marcomorain/7413064 to your computer and use it in GitHub Desktop.
Depending on how you call Date, the type changes.
parts = [1982, 5, 29]
// => [1982, 5, 29]
// This is my birthday.
new Date(parts)
// => Sat May 29 1982 00:00:00 GMT+0100 (IST)
// Month is 1-based (5 = May)
new Date(parts[0], parts[1], parts[2])
// => Tue Jun 29 1982 00:00:00 GMT+0100 (IST)
// Month is 0-based (5 = June)
// But what is the Date function?
Date === Date.prototype.constructor
// => true
d = new Date(parts)
// => Sat May 29 1982 00:00:00 GMT+0100 (IST)
s = Date.prototype.constructor.apply({}, parts)
// => "Mon Nov 11 2013 16:05:30 GMT+0000 (GMT)"
// Different answer by calling the function in this manner.
d.constructor
// => function Date() { [native code] }
s.constructor
// => function String() { [native code] }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment