Here is the recursive/trailing recursive implementation of the reverse sequence (array/string) made with JavaScript. In addition, the early adopters used a ES6 destructuring assignment + spread operator to make a more functional version (only supported arrays).Correctness can pass the test (see the demo on my Github and write a small test frame), but efficiency is mark-especially with the ES6 feature version. This is mainly written to play the functio
Provide default values when using ES6 Parameter object destructuring, but can also require the Presen Ce of certain properties.function ajax ({type="Get", the URL= Requiredparameter ("URL"), Data={}, Success= Requiredparameter ("Success"), Error= () + ={}, IsAsync=true} ={ }) {Console.log ({}) {json.stringify ({type, URL, data, success, error, IsAsync},NULL,2));} function Requiredparameter (name) {console.log (' parameter missing:"${name}"`);}Try{ajax
Term: destructuring assignment (deconstruct assignment)This is a new term introduced by JavaScript 1.7. As for the purpose, people who have used programming scripts such as MATLAB and Lua are no longer familiar with it.
VaR A = 1;VaR B = 3;[A, B] = [B, a];
In other words, multiple copies are written in one row. The main purpose is to return multiple return values, because such scripts neither have pointers nor reference parameters. Of course, it can
();map.set('first','hello');map.set('second','world');for(let item of map){ console.log(item);}for(let [key,value] of map){ console.log(key+'is'+value);}for(let [i,j] of map){ console.log(i+' is '+j);//结果同上}
If you just want to get the key name, or just want to get the key value, you can write the following
//获取键名for (let [key] of map){...}//获取键值for (let [,value] of map){...}
6. Get the specified method of the moduleAfter the module is loaded, it is often necessary to specify the variab
two are: B 2. It can be seen that clojure makes up the remaining two to form a map, the corresponding deconstruct is 2.
If you think [ C] will automatically convert the vector into a map, it will be wrong again. Let's try again.
(Defn F-N [ C] (: B c); then call (F-N: B 2) ----------> Nil
Clojure's code has no rules at all. After getting used to it, it actually follows a very simple and unified principle, which is form, evaluate, and so on. (Of course, as mentioned in clojure, clojure holds
The previous article on the deconstruction of object, this talk about array deconstruction, the concept of the same, but the writing will be somewhat different, first look at a simple example:
let [x, y] = [' A ', ' B ', ' C ']; x = ' a '; y = ' B '
Date ();
Let-text = ' The time and date is ${today.tolocalestring ()} ';
(Back to catalog) destructuring
Deconstruction allows us to use very handy syntax to directly export the values of an array or object directly to multiple variables, destructuring Arrays
Deconstruction Array
var arr = [1, 2, 3, 4];
var a = arr[0];
var b = arr[1];
var c = arr[2];
var d = arr[3];
Let [A, B, C, d] = [1, 2, 3, 4];
Cons
="+elem);
});
Output:
index = 0, Elem = a
index = 1, Elem = b
index = 2, Elem = C
The for-of loop of the ES6 supports ES6 iterations (through Iterables and iterators) and deconstruction. If you use the new method of the array enteries () to combine the deconstruction, you can achieve the same effect as the above ForEach:
Const arr = ["A", "B", "C"];
for (const [index, elem] of arr. Entries()) {
console. Log('index = ${ind
the right array corresponds to the value. No matter how deep you nest, you can still deconstruct them.
To deconstruct a nested array
destructuring Nested Arrays
const AVENGERS = ['
Natasha Romanoff ',
[' Tony Stark ', ' James Rhodes '],
[' Steve Rogers ', ' Sam Wilson ']
];
Avengers and their are
const [Blackwidow, [Ironman, Warmachine], [cap, falcon]] = Avengers;
Blackwidow = ' Nata
ECMAScript 6 (hereinafter referred to as ES6) is the next generation of JavaScript language standards. Since the current version of ES6 was released in 2015, it is also called ECMAScript 2015.In other words, ES6 is ES2015.While not all browsers are compatible with ES6 all features at this time, more and more programmers are already using ES6 in actual projects. So even if you don't plan to use ES6 now, you should know a little bit about ES6 's grammar in order to understand others.Before we form
ECMAScript 6 (hereinafter referred to as ES6) is the next generation of JavaScript language standards. Since the current version of ES6 was released in 2015, it is also called ECMAScript 2015.In other words, ES6 is ES2015.While not all browsers are compatible with ES6 all features at this time, more and more programmers are already using ES6 in actual projects. So even if you don't plan to use ES6 now, you should know a little bit about ES6 's grammar in order to understand Others.Before we form
The most commonly used ES6 featureslet, const, class, extends, super, arrow functions, template string, destructuring, default, rest argumentsThese are the most commonly used ES6 grammar, basically learn them, we can go all over the world is not afraid of! I will use the most understandable language and examples to explain them, to ensure that a look at the understanding, a learning will.Let, constThe use of these two var is similar, is used to declar
Es6 notes 3 ^_^ object, es6 notes 3 objectI. destructuring
ES6 allows you to extract values from arrays and objects in certain modes and assign values to variables. This is called Destructuring.
// Es5if (1) {let cat = 'ken'; let dog = 'lili'; let zoo = {cat: cat, dog: dog}; console. log (zoo); // Object {cat: "ken", dog: "lili" }}// ES6 can be written as follows: if (1) {let cat = 'ken'; let dog = 'lili';
Ecmascript 6 (es6) is the next-generation standard for JavaScript. Because the current version of es6 was released in 2015, it is also called ecmascript 2015.
That is to say, es6 is es2015.
Although not all browsers are compatible with all es6 features, more and more programmers are using es6 in actual projects. So even if you don't want to use es6 now, you should understand es6 syntax to understand others...
Before we officially explain es6 syntax, we must first understand Babel.Babel
Babel is
React native is the direct use of ES6 to write code, many new syntax can improve our productivity
Deconstruction Assignment
var {
Stylesheet,text,view
} = react;
This code is the new deconstruction (destructuring) assignment statement in ES6. Allows you to get multiple properties of an object and assign them to multiple variables using a single statement.
The above code is equivalent to:
var StyleSheet = React.stylesheet;
var T
;Var_dump (Swap ($a, $b), $a, $b);
The above routines will output:
null
int (2)
int (1)
Trying to get the return value of a void method gets null and does not produce any warnings. The reason for this is not to affect a higher level of approach. symmetric array destructuring¶
The short array Syntax ([]) can now be used to assign the value of an array to some variables (including in foreach). This approach makes it easier to extract values from an ar
comparison of variables and attributes, for example:
Let obj = {
name: ' Jhone ', age
: ' n ',
sex: ' Man '
} let
obja = {Name,age,sex} = obj;
Console.log (Obja.name)
The variable name,age,sex in the object and the attribute name,age,sex in object obj are compared to the assignment. Maybe you're a little confused, so let's look at the following example:
Let a= {name: "Jhon"} = {name:1};
Console.log (a)//error Invalid destructuring
. Execute all plugins in plugins
2, plugins plug-ins, in order to rely on the compilation
3, all plugins plug-in execution complete, in the execution presets preset.
4, Presets preset, in reverse order of execution. (from the last execution)
5, complete the compilation.
1, the main plug-in introduction
BABEL-PRESET-ES2015 (es2015/es6 plug-in collection)
Convert ES2015 (ES6) JavaScript code to browser-compatible JavaScript code
Arrow-functions: Arrow function
Block-scoped-func
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.