js包装对象

var str = "hello world";

str.len = 4;

console.log(str.len); //undefined

console.log(typeof str);//string

第二行代码创建一个临时字符串对象,并给其len属性赋值位4,随机销毁这个对象。

第三行通过元素的(没有修改过的)字符串值创建一个新的字符串对象,尝试读取其len属性,这个属性自然不存在,表达式求值结果为unddfined。

var str1 =new String("hello world)";

str1.len = 4;

console.log(str1.len);//4

console.log(typeof str1);//object

 

console.log(str1 == str); //true

console.log(str1 === str); //false

posted @ 2017-07-31 14:15  *﹏漸洐漸薳〆…  阅读(116)  评论(0编辑  收藏  举报