The inheritance from Date class #4037
Replies: 1 comment
-
Posted at 2014-08-25 by @gfwilliams I don't have time to look into this right now I'm afraid... However when you post code up, please can you do it as text so I can copy/paste and test? Posted at 2014-08-25 by Uhv
Posted at 2014-08-25 by @gfwilliams I just did a quick check and pasted this into node.js (changing
So presumably the code you've used isn't correct... For starters, In Espruino, you can make your code work with:
But node.js still won't work, which isn't a good sign. Maybe someone else has some ideas? Posted at 2014-08-25 by Uhv Mmm... What about methods? I'd like to have methods of Date class in my new AppDate... The way of inheritance that I 've used works good with another classes but not with Date. I woudn't like to build bulky functions to copy objects from Date to new class :-) And one more question: how can I change the time zone? Posted at 2014-08-25 by @gfwilliams Is there a reason you wouldn't just extend Date itself via Date.prototype? I'm afraid right now you can't change timezone of the date - so you'd have to add or subtract the relevant amount of hours manually. Posted at 2014-08-25 by Uhv I think, it'll be simpler to include a Date object as a component in new class that I can extend as I wish. Although by inheritance it would be more beautiful I've spied in your code the time zone is GMT+0100(BST). It's interesting how have you set it? |
Beta Was this translation helpful? Give feedback.
-
Posted at 2014-08-24 by Uhv
What is the reason that I can't inherit from Date class?

The short example is here:
The constructor of AppDate uses the constructor of Date class, but the last one doesn't create an 'ms' field! There is only an additional field 'reference' created by AppDate constructor.
In addition there are no methods of Date class in AppDate class.
Why?
Beta Was this translation helpful? Give feedback.
All reactions