0

I try to apply arguments to Date, but its not work. How I can apply arguments to native constructor Date? I tried:

var a = new (Date.bind.apply(Date, ['2010-10-10']))();

and

var a = new Date();
Date.apply(a, ['2010-10-10']);
asci
  • 2,540
  • 4
  • 16
  • 15
  • Perhaps you can expand on what exactly you are trying to achieve? – Xotic750 Sep 01 '13 at 09:02
  • Felix, I tried one of those methods and its not work. You can try it youself new (Function.prototype.bind.apply(Date, ['2010-10-10'])); – asci Sep 01 '13 at 09:08
  • Check This Solution [javascript-object-by-calling-prototype-constructor-apply][1] [1]: http://stackoverflow.com/questions/181348/instantiating-a-javascript-object-by-calling-prototype-constructor-apply – Shashank Shukla Sep 01 '13 at 09:21
  • It works fine for me: http://jsfiddle.net/pNdHT/. Granted, your code looks pretty much the same, I cannot find the problem. – Felix Kling Sep 02 '13 at 05:28

1 Answers1

1

If the parameter you are using defines a specific date, just use the usual new Date() constructor:

var a = new Date( '2010-10-10' );
Sirko
  • 72,589
  • 19
  • 149
  • 183
  • No. I need to create wrapper to Date and wrapper class can gets any params such as Date can get. Like ts, ISOString or year, month, date, etc. – asci Sep 01 '13 at 08:38
  • 2
    @asci You should edit your question and elaborate some more on what you exactly want to achieve. – Sirko Sep 01 '13 at 09:07