In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly introduces "how to use eval and with in Javascript". In daily operation, I believe many people have doubts about how to use eval and with in Javascript. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts about "how to use eval and with in Javascript". Next, please follow the editor to study!
The scope of javascript is lexical lexical scope or static scope, that is, the chain of scope is determined when it is defined. It is also mentioned that eval and with will disrupt the domain chain (dynamic scope).
Eval
Under IE: running eval () is limited by the current scope, while running execScript () ignores the current scope and executes directly under the global scope.
Under Firefox: the effects of eval () and window.eval () are not the same, which is strange, after all, under FF, eval==window.eval. The former is limited by the current scope, while the latter ignores the current scope and executes in the global scope (equivalent to IE's execScript ()).
Someone wrote a more popular article, refer to this article.
With
With temporarily modifies the scope chain.
Function a () {with (b) {...}} a ()
When the function an is defined, the scope chain of an is determined, and let's assume that the top of this chain is the global object window.
When the function an is executed, the javascript engine generates a call object and adds it to the tail of the scope chain (after the window object). When the statement runs to with (b), b is added to the tail of the scope chain, so the variable search within the with will first look on the b of the chain-- > and then find the window in the call object of a. After the statements in the with are executed, the scope chain is restored (b is removed from the scope chain).
This is the microcosm of the example code runtime.
With is not recommended because it operates the scope chain (move in, move out, how tired) and the execution is inefficient.
Some people may think that with can save code, such as
With (document.forms [0]) {name.value='';address.value='';email.value='';}
You can write a lot less document.forms [0]
In fact, defining a local variable to replace b in with can also achieve the same goal, with no loss of efficiency.
Var c=document.forms [0]; c. Name.valueworthy examples are complete. At this point, the study on "how to use eval and with in Javascript" is over, hoping to solve everyone's doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.