JS中对象是可变的控件集合,对象的内容是可以更改的,可以为它添加任意属性或删除,而基本数据类型虽然拥有方法,但它们的值是不可变的,之所以它们拥有方法,是因为当它们调用方法是,后台会自动创建一个相映包装类型的一个实例,然后在实例上调用指定方法,最后再销毁该实例;例如:
1 var s1="some text"; 2 var s2=s1.substring(2);
就相当于以下操做:
1 var s1=new String("some text"); 2 var s2=s1.substring(2); 3 s1=null;