Javascript Tips (Updating...)
1.判断一个object的类型
if ((typeof o == "object") && (o.constructor == Date)) // Then do something with the Date object... if ((typeof o == "object") && (o instanceof Date)) // Then do something with the Date object...
| Variable | typeof Variable | Variable.constructor |
|---|---|---|
| { an: “object” } | object | Object |
| [ “an”, “array” ] | object | Array |
| function(){} | function | Function |
| “a string” | string | String |
| 55 | number | Number |
| true | boolean | Boolean |
| new User() | object | User |
2. javascript中的字符串连接
众所周知在C#中,StringBuilder的效率比String.Concat的效率要高几个数量级
具体参阅:String.Concat versus Text.Stringbuilder
javascript里面也有同样问题,之前做了一个小测试,看看各浏览器的链接效率。
Which browser is faster :<
可以看出,在除了IE的浏览器内,都对Js的字符串连接操作做了优化。so在IE中做大量的字符串连接操作时,应该考虑下性能问题咯。

浙公网安备 33010602011771号