This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
一、 错误实现 | |
var array1 = new Array("1","2","3"); | |
var array2; | |
array2 = array1; | |
array1.length = 0; | |
alert(array2); //返回为空 | |
这种做法是错的,因为javascript分原始类型与引用类型(与java、c#类似)。Array是引用类 | |
型。array2得到的是引用,所以对array1的修改会影响到array2。 | |
二、 使用slice() | |
可使用slice()进行复制,因为slice()返回也是数组。 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//平台、设备和操作系统 | |
var system ={ | |
win : false, | |
mac : false, | |
xll : false | |
}; | |
//检测平台 | |
var p = navigator.platform; | |
alert(p); | |
system.win = p.indexOf("Win") == 0; |
NewerOlder