In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains "how to use JS". Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Now let the editor take you to learn how to use JS.
1. The Function constructor Function () constructor is not very common, but it is necessary to know about it.
Whether through a function definition statement or a function direct quantity expression, the function definition uses the function () keyword. A single function can also be defined by the Function () constructor, such as:
Const diff = new Function ('averse,' baked, 'return a-b'); diff (202.13) / / 7
The actual effect of this line is equivalent to the following line of code:
Const diff = function (a, b) {return a-b} diff (20,13)
2. With statement
JavaScript has a with keyword, and the with statement was originally intended to provide a namespace-style sketch for hierarchical object access. That is, in the specified code area, the object is called directly through the node name.
We already know that variable names are resolved using the scope and scope chain of variables (that is, a list of objects retrieved sequentially), and the with statement is used to temporarily modify the scope chain, and its syntax is:
With (object)
This statement effectively adds object to the header of the scope chain, then executes statement, and then returns the scope chain to its original state.
Const book = {author: 'frontend console.log', title:'I don't know the six other things that can be done with JS'} with (book) {console.log (author); / / frontend console.log (title); / / I don't know the six other things that can be done with JS}
JavaScript code that uses with statements is difficult to optimize, so it is much slower than equivalent code that does not use with statements. Also, function definitions and variable initialization in with statements can produce surprising and contradictory behavior, so we avoid using the with` statement.
3. + operator
We can use the + operator to convert a string to a number. You don't need to use functions such as parseInt () or parseFloat () unless you want to parse to a specific number type.
Const nr = + '1.5; nr + 1; / / 2.5
4. Assign attributes to a function We can assign attributes to a function. Next, you can create a configurable function by assigning specific properties to the function.
Function sayHello () {if (sayHello.country = 'US') {return alert (' Hi there');} if (sayHello.country = 'FR') {return alert (' Bonjour!');} if (sayHello.country = 'GR') {return alert (' Guten Tag!');} return alert ('Hi');} sayHello.country =' FR'; sayHello () / / alert ('Bonjour!')
We can use these function properties as counters or "static variables".
5. Arguments.callee.caller
We can use arguments.callee.caller to see which function called the current function. The default value of the argumentsJS normal function. Arguments.callee.caller tells us who called the function. Similar to having only one layer of console.trace ().
Function sayHello () {console.log (arguments.callee.caller) / / [Function: start]} (function start () {sayHello ()}) ()
In addition, arguments.callee refers to the function that is currently running.
Function sayHello () {console.log (arguments.callee) / / [Function: sayHello]} (function start () {sayHello ()}) ()
6. Void operator
The void operator evaluates the given expression and returns undefined.
Void (1); / / undefined void (true); / / undefined void (false); / / undefined void ({}); / / undefined
If you ask why you only need to return undefined instead of returning, you need a special keyword undefined: because before ES5, you can actually name a global variable undefined, like this: var undefined = "hello" or var undefined = 23, which is acceptable to most browsers; undefined does not guarantee that identifiers are actually indeterminate. Therefore, to return the actual undefined value, use the void operator. It is not a very popular operator and is rarely used.
At this point, I believe you have a deeper understanding of "how to use JS". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
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.