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()
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()
arrow function has no this equal to the external this
external is the object pointed to by a variable o and o is defined in the global
so this is global window
arrow function is determined when it is defined, it is an external this.
because the arrow function is not bound to the context
Previous: Use tp5 combined with Mini Program's wx.request to obtain background data
Next: How to solve the problem of lack of precision from JAVA long to double?
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 but put it into four div separately, how to realize it? 0 < div > 5 < div > 2 < div > 1 < div > ...
how do I use generator to achieve the following functions? function f1(){ return new Promise((resolve,reject) =>{ setTimeout(() =>{ resolve(1); },1000) }) } function f2(valu...
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 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 ...
converts the current time to a timestamp and saves it to localStorage. uses another time to generate a timestamp to determine whether the interval between the two is greater than one month. or not switch to a timestamp, as long as you can determine t...
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...
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...
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...
* 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(...
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...
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...
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>` ...
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, ...
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 ...
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...
let keys = [ a , b ] let vals = [ [111, 222], [333, 444] ] expected result: [{a:111,b:222},{a:333,b:444}] ...
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"...
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 ...
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...