• 【JS】引用类型之Global


    Global是一个固有对象(全局),不属于任何对象,目的是把所有全局方法集中在一个对象中。

    这里挑几个常用的global方法

    1、URI编码解码方法

    编码(encodeURI/encodeURIComponent)

    var uri = "http://www.wrox.com/illegal value.htm#start";
    
    //"http://www.wrox.com/illegal%20value.htm#start"
    alert(encodeURI(uri));
    
    //"http%3A%2F%2Fwww.wrox.com%2Fillegal%20value.htm%23start"
    alert(encodeURIComponent(uri));

    解码(decodeURI/decodeURIComponent)

    var uri = "http%3A%2F%2Fwww.wrox.com%2Fillegal%20value.htm%23start";
    
    //http%3A%2F%2Fwww.wrox.com%2Fillegal value.htm%23start
    alert(decodeURI(uri));
    
    //http://www.wrox.com/illegal value.htm#start
    alert(decodeURIComponent(uri));

    2、eval()

    该方法相当于一个JS解析器,能够执行传入的任何JS代码

    eval("alert('hello')");
    //等价于alert('hello');
    
    eval("function sayHello(){alert('hello');}");
    sayHello();//hello
    
    //将一个字符串转换成一个对象
    eval("var obj=" + response.responseText);
    alert(obj.xxxx);

    window对象既是Global的属性,同时它也是一个Global对象

  • 相关阅读:
    ssh.sh_for_ubuntu1604
    ssh.sh_for_ubuntu1404
    ssh.sh_for_ubuntu1204
    ssh.sh_for_centos
    raw,cow,qcow,qcow2镜像的比较
    Oz 创建Windows2008R2镜像
    Oz 创建Ubuntu镜像
    Oz 创建Debian8镜像
    Oz 创建CentOS7镜像
    Oz 创建CentOS6镜像
  • 原文地址:https://www.cnblogs.com/yangzhilong/p/3014689.html
Copyright © 2020-2023  润新知