Jump to content

Date.toString() is invoked first


graduate
 Share

Recommended Posts

Does the Date object has a special behavior when it is used in an expression?

var obj = {}, date= new Date();  20 + obj; // obj.valueOf() is called first20 + date; // date.toString() is called first, the result is a string

If I try to emulate the Date object I could not do it because in the "x + y" expressions I can't to force my object to invoke toString() method first.

Edited by graduate
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...