zoukankan      html  css  js  c++  java
  • 渡一 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
        }
    }
  • 相关阅读:
    12. nc/netcat 用法举例
    7. 由一道ctf学习变量覆盖漏洞
    11. 几点基于Web日志的Webshell检测思路
    约瑟夫环
    栈结构的经典算法题
    二叉查找树之二
    fork与vfork
    数组常见算法题
    赛马问题
    fibonacci 数列及其应用
  • 原文地址:https://www.cnblogs.com/lisa2544/p/15417234.html
Copyright © 2011-2022 走看看