Besides js implicit conversion

Besides js implicit conversion

Their finishing a whole rules are as follows:

Date walk default toString, toString returns if the object, then the view valueOf
convert other objects, the default valueOf go, but if valueOf returns the object, then try toString


//比如示例如下:
//默认的对象隐式转换是走 valueOf
   var o1 = {
       valueOf: function(){
           return 1;
       },
       toString: function(){
           return 9;
       }
   }

   console.log(o1 == 1); // true



 //Date 默认走 toString
 //比如 new Date("1970/01/02")

new Date("1970/01/02").toString() == "Fri Jan 02 1970 00:00:00 GMT+0800 (中国标准时间)"; //true, 默认的 toString 的内容

new Date("1970/01/02") == "Fri Jan 02 1970 00:00:00 GMT+0800 (中国标准时间)"; //true, 默认的 toString 的内容

new Date("1970/01/02").valueOf() == 57600000 // getTime的内容



Guess you like

Origin www.cnblogs.com/asdfq/p/10994198.html