zoukankan      html  css  js  c++  java
  • javascript的try catch和es5标准模式

    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 !!!

  • 相关阅读:
    在小程序中实现 Mixins 方案
    watch监听(数组或者对象)
    --socket---网络通信---
    requests实战之破解百度翻译
    nmap命令
    selenium模块的基本使用
    谷歌无头浏览器+反检测
    模拟登录QQ空间
    动作链和iframe的处理
    selenium其他自动化操作
  • 原文地址:https://www.cnblogs.com/lyjfight/p/13827185.html
Copyright © 2011-2022 走看看