javascript 小篇絮

来源:互联网 发布:mac上怎么解压缩 编辑:程序博客网 时间:2024/04/18 19:54

Object.prototype.toString.call(args)进行类型判断

Object.prototype.toString.call('123')  [object String]

Object.prototype.toString.call([123])  [object Array]

Object.prototype.toString.call({a:123})  [object Obeject]

Object.prototype.toString.call(/123/)  [object RegExp]

Object.prototype.toString.call(123)  [object Number]

Object.prototype.toString.call(undefined)  [object undefined]

Object.prototype.toString.call(null)  [object Null]


Array.prototype.slice.apply(arguments)

当遇到需要将参数转换为数组时可以改方法。这种方法是有效的,而且在主流浏览器上都测试通过。

0 0
原创粉丝点击