codecombat/esper.js

Date

Closed this issue · 4 comments

I wanted to add the native Date like in issue #6: addGlobal('Date',Date').

Usingnew Date works (new Date('December 25, 1995 23:15:30');) but methods aren't working ( Xmas95.getMonth()).

var Xmas95 = new Date('December 25, 1995 23:15:30'); // works
var month = Xmas95.getMonth(); // doesn't work

console.log(month);

Is there a way to expose the methods?

The crux of the issue here is that the Date() constructor knows if its being called as a constructor or not. I just pushed some code to fix this. ef34f6a

Leaving this open so I remember to write some tests to cover it.

@basicer Something's a bit strange using the ef34f6a build, though Xmas95.getMonth() runs, Xmas95 holds today's date instead of what is passed into the constructor: 'December 25, 1995 23:15:30'.

Good catch. Should have written the tests first :D. Try now.

Thanks it's working now.