为什么要尽量少使用new来创建基本类型呢
举个🌰:
var string = 'cloth';
string.color = 'red'
console.log(string.color) // undefined
因为new 但是用new创建的时候你会发现
var string = new String('cloth');
string.color = 'red' // red
这样在使用上回造成混淆,使用
typeof string //obj
会发现是一个对象
为什么要尽量少使用new来创建基本类型呢
举个🌰:
var string = 'cloth';
string.color = 'red'
console.log(string.color) // undefined
因为new 但是用new创建的时候你会发现
var string = new String('cloth');
string.color = 'red' // red
这样在使用上回造成混淆,使用
typeof string //obj
会发现是一个对象