I know that there are many functions of parentheses () in JS, but currently only discusses the examples given below
10.toString() // Invalid or unexpected token
(10).toString() // "10"
{}+"" // 0
({})+"" // "[object Object]"
10.toString() // Invalid or unexpected token
(10).toString() // "10"
{}+"" // 0
({})+"" // "[object Object]"
10.toString() //
(10).toString() // 5 toString
{}+'' // {} +''
({})+'' // {} +''
in your example, simply using ()
is equivalent to defining a immediate execution function , and the callback object is the content wrapped by ()
(10) //10
({}) //{}
with this feature, you can also add parameters to this function
(v => v + 10)(10); //20
We also often use this feature to simplify our code
[1, 2, 3].map(v => {
return {value: v};
});
can be simplified to the following
[1, 2, 3].map(v => ({value: v}))
.
: is the decimal point
and is also the attribute accessor
.
{}
: is code block
and is also object
.
parentheses, like parentheses in mathematical operations, obediently define the priority (highest) of the operator. Avoid ambiguity like the one above.
operators like this. The most direct way to find out all its features is to consult the specification.
http://www.ecma-international...
brackets can enhance the expression of meaning and reduce ambiguity.
assigns the literal quantity to the anonymous variable
{} +''and ({}) +' 'return the same, both [object Object]
antd-mobile UItabbar tab tabbarIndextab the problem is how to display the page under the corresponding Tab path after clicking the switch, such as why the navigation path home nav, above adds the path file but cannot access it? ...
projects generated by webpack4 can be directly npm install before, Open this project today and re-npm install the total pop-up prompt githubnpm installwindow C:UsersAdministratorDesktopTms>npm installnpm ERR! Error while executing:npm ERR! C:Program ...
request the backend to submit parameters to return a url similar to online silver recharge. It is risky to contact the merchant after entering the operation prompt. What is the situation of contacting the merchant? Is it necessary to submit form forms in...
I would like to ask you, recently, I am learning that requirejs, knows that r.js is used to package requirejs modules. But now I want to package the requirejs module with r.js in conjunction with gulp. read a lot of tutorials, and many of the tutorial...
< H2 > an error was reported when configuring vue ssr server rendering. I have been looking for this error for a long time, but I really don t know how to solve it. I hope to have some advice < H2 >. server-render.js const ejs = require( ejs ) mod...
do paging. On the first page, the background res.render ( "admin article.html ", {data:data}) Click the second page to re-query the database and query successfully to make sure that the data has changed. The page has not changed. What should be done? ...
there is html in business because the company requires inspection record < custom-form > { "form_element_id ": "10081 " in html. "title ": "u88f1u7ccau5de a tag like this then installs the custom-form as a tag that can be recognized by html thro...
is currently developing an official account that uses vue s hash mode for vue, routing, but the Android phone will modify my custom link during the test. I will intercept all the addresses after-sharp for example, my custom sharing link is http: e...
use node as the middle tier, a build tool made by gulp. When I submit the code to the server and recompile, and then refresh the page, dom always shows old resources, but both css and js have been updated. It has been recompiled countless times, and the...
footer.html footer.js html has been rendered, but the value of span is still the original value. how to set the value of span dynamically? ...
such as the title, I want to design and develop an online 3D editing software in my spare time, but I don t know how to build it. I m afraid that if I find it wrong in the middle of the writing, I will come back to change the structure, then it will b...
do you share the web pages in Weibo with your friends? do you have a receipt? is there a successful callback when Weibo is shared with Wechat s moments? ...
the official website says that this is the function called after destroying the vue instance. Mine just left the routing interface and did not call it. This is because no vue scaffolding generated only one root instance that destroyed the page. Is th...
cycle highlighting in echart s line chart, that is, every 5 seconds, one line brightens and the rest darkens. ...
the front end requests to report 404, but the backend confirms that the file can be received . Code in node service server.js var storage = multer.diskStorage({ destination: function (req, file, cb) { cb(null, . upload ); }, filename: f...
I enter the vue-awesome-swiper, page used in vue2.0 and request an interface according to the parameters in an array list. Every time the requested data returns the result, I save it in an array, and then swiper takes the data from these arrays to rende...
this is how I used to add error prompts at home if the code went wrong. The browser will print it on the screen. But now this method of writing does not respond to the configuration in the company. I don t know why ...
do a page for a period of time, a class for 30 minutes. The data structure that the backend wants is like this 2018-09-17|09:00-09:30,2018-09-18|09:30-11:00,2018-09-19|10:00-11:30,2018-09-20|10:30-11:00,2018-09-21|11:00-11:30,2018-09-22|11:30-12:00 I ...
when I was using react-native to develop Android app, I encountered the problem of immediate execution of setTimeout. I found a lot of information on the Internet and tried to no avail, so I came to ask for help. No, no, no. here is my code _heig...
Why use json object strings here, as shown in the figure? Then the front-end js parses the string into an object with JSON.parse (), so why not just use the normal js object form in the first place? ...