-
-
Save marcomorain/7413064 to your computer and use it in GitHub Desktop.
Depending on how you call Date, the type changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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