In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article will explain in detail what are the seven details that beginners must pay attention to in JavaScript. The content of the article is of high quality, so the editor will share it with you for reference. I hope you will have a certain understanding of the relevant knowledge after reading this article.
(1) simplify the code
JavaScript is very simple to define objects and arrays. We want to create an object, which is generally written like this:
Var car = new Object (); car.colour = 'red'; car.wheels = 4; car.hubcaps =' spinning'; car.age = 4
The following writing methods can achieve the same effect:
Var car = {colour:'red', wheels:4, hubcaps:'spinning', age:4}
The latter is much shorter, and you don't have to repeat the object name.
In addition, there is also a concise way to write arrays. In the past, we declared that arrays were written like this:
Var moviesThatNeedBetterWriters = new Array ('Transformers','Transformers2','Avatar','Indiana Jones 4')
A more concise way of writing is:
Var moviesThatNeedBetterWriters = ['Transformers','Transformers2','Avatar','Indiana Jones 4']
For arrays, there is also something special about concatenated arrays. You will find that a lot of code defines objects like this:
Var car = new Array (); car ['colour'] =' red'; car ['wheels'] = 4; car [' hubcaps'] = 'spinning'; car [' age'] = 4
This is crazy, don't be confused, "associative array" is just an alias for the object.
Another way to simplify code is to use ternary operators, for example:
Var direction; if (x < 200) {direction = 1;} else {direction =-1;}
We can replace this with the following code:
Var direction = x < 200? 1:-1
(2) use JSON as the data format
The great Douglas Crockford invented the JSON data format to store data, and you can use native javascript methods to store complex data without any additional transformations, such as:
Var band = {"name": "The Red Hot Chili Peppers", "members": [{"name": "Anthony Kiedis", "role": "lead vocals"}, {"name": "Michael 'Flea' Balzary", "role": "bass guitar, trumpet, backing vocals"}, {"name": "Chad Smith", "role": "drums" Percussion "}, {" name ":" John Frusciante "," role ":" Lead Guitar "}]," year ":" 2009 "}
You can use JSON directly in JavaScript, or even as a format returned by API, which is used in many API, such as:
Function delicious (o) {var out ='; for (var item0)
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.