-
In the chained promise function, how to determine which promise threw the error
I need to implement in a chained promise function, any function error in the middle terminates the program, and can catch the error function, and then perform different operations according to different error functions. How can the following code be imp...
-
Read a number, such as 521, change this number to 0521, and put it into four div, how to achieve?
read a number, such as 521
change this number to 0521
but put it into four div separately, how to realize it?
0 < div > 5 < div > 2 < div > 1 < div >
...
-
How to use Generator to implement a chain dependent function?
how do I use generator to achieve the following functions?
function f1(){
return new Promise((resolve,reject) =>{
setTimeout(() =>{
resolve(1);
},1000)
})
}
function f2(valu...
-
This problem of js Arrow function
I don t understand why this is window in this broken code. Thank you for your understanding. Thank you.
var o = {
fn:() => {
console.log(this)
}
}
o.fn()
...
-
How does js implement a general regular validation form method (minimum code)
1. How to implement a general regular validation form with the least amount of code
= project, 1. Login has two input (verify mailbox, password 10 digits + letters)
2. input ()
both forms are displayed after input loses focus (correct or w...
-
I want to use some of the constants defined in state to assign default values to the drop-down box and v-model this variable in the data of the component, what should I do?
I m going to assign the default value of 1 to the value of the drop-down box and bind this variable;
<select v-model= selectValue >< select>
but just let
data(){
return{ selectValue:1 }
}
this type of writing is not readable, so I ...
-
What is the most elegant way to implement an array of ES6 objects based on a property?
A solution that conforms to the meaning of the question
function unique(arr) {
const res = new Map();
return arr.filter((a) => !res.has(a) && res.set(a, 1))
}
because map key is unique, you can change the an in res.has (a) to whate...
-
How to understand closures
1. Use var:
var a = [];
for (var i = 0; i < 10; iPP) {
a[i] = function () {
console.log(i);
};
}
a[6](); 10
2. Use let
var a = [];
for (let i = 0; i < 10; iPP) {
a[i] = function () {
console.log(i);
};
}
a[6](); 6
quest...
-
Es6, removes the contents of one array from another array
my code has bug, and then I checked to write = = as = .
A [1,2,3,4,5,6,7]
B [2,3,4]
after deletion
A [1,5,6,7]
this.selectRightTableData.forEach(item => {
this.rightTableData.splice(this.rightTableData.findIndex(v => v.id = item.id...
-
How to handle asynchronous queuing in dva
* deleteDetails({payload}, {call, put}) {
const result = yield call(deleteDetails, {payload});
if (result.code !== 200) {
throw result.msg;
} else {
Toast.success(result.msg, 1);
yield put(routerRedux.goBack(...
-
How does es6's Set customize the de-repetition rules? How can an array of objects be duplicated according to a column property?
for example, duplicates according to the name attribute in the an array element.
is this the simplest way?
function unique(arr) {
const res = new Map();
return arr.filter((a) => !res.has(a.name) && res.set(a.name, 1))
}
reference...
-
Deconstruction of ES6- function
The deconstruction of the function does not quite understand the red arrows in this. Why undefined? Is it not true that when let {XMagi y} = {XRO 0PersonyGl} , x can output equal to 0LI YQ 1, although XMagi y is a pattern and the assignment is assig...
-
JS rendering output string concatenation html should not have a comma
navMenuData.sort(sortID).map((item) => {
let option;
if (item.options) {
let optionJSON = JSON.parse(item.options)
option = optionJSON.map((item) => {
return `<a href="-sharp">${item.name}< a>`
...
-
What is the most elegant way for js to add another array to the end of the array?
is there a method like push, but instead of inserting an element into an array, add another array similar to java s addAll method
all I know so far is concat, but he returns the new array instead of making changes on the original array,
...
-
The problem of clock function in Generator function in ES6
var clock = function*() {
while (true) {
console.log( Tick! );
yield;
console.log( Tock! );
yield;
}
};
you can see that the state machine implemented by the Generator function does not need to set initial variables or switch ...
-
It doesn't matter how gracefully es6 judges that the values contained in two arrays are exactly the same.
this is what I do now. Is there a better way?
let flag = true
const listA = [1, 2, 3]
const listB = [2, 3, 4]
if (listA.length !== listB.length) {
flag = false
} else {
listA.forEach(item => {
if (listB.indexOf(it...
-
Solve the problem of array processing?
let keys = [ a , b ]
let vals = [
[111, 222],
[333, 444]
]
expected result:
[{a:111,b:222},{a:333,b:444}]
...
-
Js array operation
var str = "abc-a,add-a,ccc-b,ccc-d,abc-a,abc-b,abc-f,tbg-g "; convert the above string to the following array form:
var arr = [
{"name" : "abc", "nameIdx":[{"site" : "a"}]},
{"name"...
-
How to transfer parameters asynchronously by js?
I have several asynchronous function operations, but I want these asynchronous operations to be performed sequentially, I want to use queues, and each function needs to pass parameters. I think of the middleware of koa2, but how do I implement it? Or is ...
-
About the understanding of the default values of es6 function parameters?
var x = 1;
function foo(x, y = function() { x = 2; }) {
var x = 3;
y();
console.log(x);
}
foo() 3
x 1
the above is the penultimate example of the scope of the function in the book introduction to es6 written by teacher Ruan Yifeng . Teache...