• The "with" keyword in Javascript


    The "with" keyword is used to specify an object to which all of the unreferenced properties and methods in a following block of code are to be applied.

    for example:

    Instead of coding

    var x = document.body.scrollLeft;
    document.write('text1');
    document.write('text2');
    document.write('text3');

    you could use

    with document {
    var x = body.scrollLeft;
    write('text1');
    write('text2');
    write('text3');
    }

    Of course using this construct results in code that may be somewhat shorter but it will also take a lot longer to run since each variable within the with block needs to be checked to see whether or not it is a property of the object that the with block references.

    A more efficient coding that is almost as short is where you assign a much shorter name to reference the object and use that instead of the original object name. For example:

    var d = document;
    var x = d.body.scrollLeft;
    d.write('text1');
    d.write('text2');
    d.write('text3');
    No replies - reply
     

  • 相关阅读:
    Netty简单聊天室
    JDK环境变量配置
    EasyUI Tabs
    NIO(五)
    NIO(四)
    银行对公业务和对私业务
    mysql常用操作
    LInux安装MySQL5.7.24详情
    Python3 SMTP发送邮件
    linux下sendmail邮件系统安装详情
  • 原文地址:https://www.cnblogs.com/jinweijie/p/566610.html
Copyright © 2020-2023  润新知