3.13. Primitive Datatype Wrapper Objects
each of the three key primitive datatypes has wrapper , that cantains the save primitive data value, but it also defines properties and mathods. when you try to access a property or method of the primitive datatypes, JavaScript internally creates a wrapper object for it.
eg. var len = s.length; s remains a string, a new transient String object is created for you to access the length property, and then the trainsient object is discarded.
3.14. Object-to-Primitive Conversion
非null的object转成Boolean时,就被转换成true.
object转成数字的时候,是调用valueOf()方法,如果没有返回一个primitive value,将调用toString()方法把string转成number
本文探讨了JavaScript中三种关键原始数据类型的包装对象及其特性,包括如何通过这些包装对象访问属性和方法。此外,还讨论了非null对象到原始类型的转换过程,例如对象转为布尔值时总是变为true,以及对象转为数字时的具体实现方式。

被折叠的 条评论
为什么被折叠?



