try catch
try { console.log('a') console.log(b) } catch (e) { console.log(e.name + ' : ' + e.message) //执行 }
e.name有六种
1.EvalError: eval()的使用与定义不一致
2.RangeError: 数值越界
3.ReferenceError: 非法或不能识别的引用数值
4.SyntaxError: 发生语法解析错误
5.TypeError: 操作数类型错误
6.URLError: URL处理函数使用不当
ES5 严格模式 ES3.0与ES5.0冲突的部分就是用ES5.0(不再使用ES3.0的一些不规则语法), 否则就是用ES3.0
看如下例子
"use strict"; //ES5.0的严格模式 function test() { console.log(arguments.callee) //报错 console.log(test.caller) //报错 } function demo() { test() } demo() with(document) { //报错 write('abc') } //变量赋值前必须申明 a = 2 //报错 //局部的this必须赋值 console.log(this) //window function test() { console.log(this) //undefined, 预编译不再指向window } test() //形参不能重复 function test(name, name) { //报错 console.log(name) } test(1) //拒绝属性重复,不报错 var obj = { name: 'a', name: 'b' } //不能eval
end !!!