2

As a corollary to this question, if you created an object in javascript using the syntax new (Date) how would you pass in any constructor args/params?

In other words is there an equivalent of new Date(2000) or is that just how you would do it?

Community
  • 1
  • 1
Andrew Young
  • 1,779
  • 1
  • 13
  • 27
  • Although you _can_ do this (as per the answers already posted), I don't understand why you would want to. Even without parameters, the parentheses around `(Date)` are redundant, so why include them? – nnnnnn Nov 23 '11 at 01:46
  • yeah. my sentiments exactly. but i just had to ask. – Andrew Young Nov 23 '11 at 01:54

2 Answers2

2

The parens return the result of the contained expression, so this will work:

new (Date)(2000);

This is the same as:

new Date(2000);
gilly3
  • 87,962
  • 25
  • 144
  • 176
0

Have you tried: new (Date)(2000)? Not exactly pretty code...

Torsten Becker
  • 4,330
  • 2
  • 21
  • 22