前言
JavaScript总结笔记篇仅是记载本人学习过程中的一些总结,为了梳理一下知识点,督促自己不断加强学习。文中有些是源自官网,有些是搜集资料,有些是个人观点,难免存在某些知识点疏漏或者是有错误的地方,如果错误之处,希望看到的小伙伴能及时提个醒,避免误导其他小伙伴,也希望我的总结能帮助到正在学或者是将要学习JavaScript的小伙伴们!大家一起努力,早日成为IT界的大神!
try...catch、es5严格模式
一、try…catch
(一)Error.name的六种值对应的信息:
1.EvalError: eval()的使用与定义不一致
2.RangeError:数值越界
3.ReferenceError:非法或不能识别的引用数值
4.SyntaxError:发生语法解析错误
5.TypeError:操作数类型错误
6.URIError:URI处理函数使用不当
Ps:在try里面发生错误,不会执行错误后的try里面的代码
二、es5严格模式
(一)用法
1.严格全局 模式
2.局部函数内严格模式(推荐)
function demo () {
console.log(arguments.callee);
}
demo();
function test () {
"use strict";
console.log(arguments.callee);
}
test(); //es5严格模式下会报错
(二)“use strict”
就是一行字符串,不会对不兼容严格模式的浏览器产生影响
(三)
1.不支持with(改变作用域链,with里面的代码会作为作用域链的最顶端)、arguments.callee、func.caller
var obj = {
name : "obj"
}
var name = 'window';
function test () {
var name = "scope";
with (obj) {
console.log(name); // obj
}
}
test();
var org = {
dp1 : {
xu : {
name : "abc",
age : 8
},
lw : {
name : "def",
age : 8
}
}
}
with (org.dp1.xu) {
console.log(name); //"abc"
}
2.变量赋值前必须声明
3.局部this必须被赋值(Person.call(null/undefined)赋值什么就是什么)
"use strict";
function test () {
console.log(this);
}
test(); //this为undefined
4.拒绝重复属性和参数
扩展:
// es3.0都不能使用eval();
var a = 123;
eval("console.log(a)"); //123