渡一 16-1 try..catch,es5标准模式

//在try里面发生的错误,不会执行错误后的try里的代码
//try后面的代码继续执行;
try{
    console.log("a");
    console.log(b);
    console.log("a");
}catch(e){
    console.log(e);
}
console.log(b)

output:a d

错误类型
EvalError:eval()的使用与定义不一致
RangeError:数值越界
ReferenceRrror:非法或不能识别的引用数值
SyntaxError:语法解析错误
TypeError:操作数类型错误
URLError:URL处理函数使用不当

es5严格模式

两种用法
全局严格模式
局部函数内严格模式(推荐)
格式 "use strict"
不支持with,arguments.callee,function.caller;
变量赋值前必须声明,局部this必须被赋值(Person.call(null/undefined)赋值什么就是什么),拒绝重复属性和参数

function demo(){
    console.log(arguments.callee);
}
function test(){
    "use strict";
    console.log(arguments.callee); //报错
}
test();
"use strict";
function Test(){
    console.log(this);
}
Test.call(123); //这里会把123变成Number(123);
var org = {
    dp1:{
        jc:{
            name:"abc",
            age:123
        },
        deng:{
            name:"xiaodeng",
            age:234
        }
    },
    dp2:{

    }
}
with(org.dp1.jc){
    console.log(name) //abc 这里的作用域是with定义中的
}

with(document){
    write("a");
}
var obj = {
    name:"obj";
}

var name = "window";

function test(){
    var name = "scope";
    with(obj){
        console.log(name) //obj
    }
}
原文地址:https://www.cnblogs.com/lisa2544/p/15417234.html