es2017

How can I remove an event listener no matter how the callback is defined

自闭症网瘾萝莉.ら 提交于 2019-12-31 04:06:11
问题 For years I ran into problems trying to remove an event listener in JavaScript. Often I would have to create an independent function as the handler. But that is just sloppy and, especially with the addition of arrow functions, just a pain. I am not after a ONCE solution. This needs to work in all situations no matter HOW the callback is defined. And this needs to be raw JS so anyone can use it. The following code works fine since the function clickHandler is a unique function and can be used

Why are await and async valid variable names?

社会主义新天地 提交于 2019-12-17 23:29:48
问题 I was experimenting with how / is interpreted when around different keywords and operators, and found that the following syntax is perfectly legal: // awaiting something that isn't a Promise is fine, it's just strange to do: const foo = await /barbaz/ myFn() Error: Uncaught ReferenceError: await is not defined It looks like it tries to parse the await as a variable name ..? I was expecting await is only valid in async function or maybe something like Unexpected token await To my horror, you

Dynamic import in different folder

帅比萌擦擦* 提交于 2019-12-13 03:56:35
问题 I have some trouble to import dynamicaly a class. I use alias for this projet : config.resolve.alias = { App: path.resolve('./src/'), Reactive: path.resolve('./app/') } I want to import a list of class : const classes = { foo: 'App/Foo', bar: 'App/Bar' }; let list = {}; for(var c in classes) { (async (k, v, list) => { const m = await import(`${v}`); list[k] = new m.default(); })(c, classes[c], list); } This script is called in app , and all imported classes in src . The error is simple :

How can I remove an event listener no matter how the callback is defined

三世轮回 提交于 2019-12-02 05:24:02
For years I ran into problems trying to remove an event listener in JavaScript. Often I would have to create an independent function as the handler. But that is just sloppy and, especially with the addition of arrow functions, just a pain. I am not after a ONCE solution. This needs to work in all situations no matter HOW the callback is defined. And this needs to be raw JS so anyone can use it. The following code works fine since the function clickHandler is a unique function and can be used by both addEventListener and removeEventListener : This example has been updated to show what I have

Why are await and async valid variable names?

孤街浪徒 提交于 2019-11-28 21:15:33
I was experimenting with how / is interpreted when around different keywords and operators, and found that the following syntax is perfectly legal: // awaiting something that isn't a Promise is fine, it's just strange to do: const foo = await /barbaz/ myFn() Error: Uncaught ReferenceError: await is not defined It looks like it tries to parse the await as a variable name ..? I was expecting await is only valid in async function or maybe something like Unexpected token await To my horror, you can even assign things to it: const await = 'Wait, this actually works?'; console.log(await); Shouldn't

Property 'entries' does not exist on type 'ObjectConstructor'

有些话、适合烂在心里 提交于 2019-11-28 08:53:55
I'm working on an ng2 implementation. I'm using the following function call to convert an object to an array: var authors = Object.entries(responseObject.Authors); This is a standard js function. However, the ts compiler returns the following error: "Property 'entries' does not exist on type 'ObjectConstructor'" Based on a quick google it appears that the solution may be to change the compilerOptions target property from es5 to es6. However, after some previous research for a previous issue, I thought that I was able to leverage es6 functionality by including the additional "lib" property on

Property 'entries' does not exist on type 'ObjectConstructor'

与世无争的帅哥 提交于 2019-11-27 02:29:32
问题 I'm working on an ng2 implementation. I'm using the following function call to convert an object to an array: var authors = Object.entries(responseObject.Authors); This is a standard js function. However, the ts compiler returns the following error: "Property 'entries' does not exist on type 'ObjectConstructor'" Based on a quick google it appears that the solution may be to change the compilerOptions target property from es5 to es6. However, after some previous research for a previous issue,

Waiting for more than one concurrent await operation

大城市里の小女人 提交于 2019-11-25 23:35:32
问题 How can I change the following code so that both async operations are triggered and given an opportunity to run concurrently? const value1 = await getValue1Async(); const value2 = await getValue2Async(); // use both values Do I need to do something like this? const p1 = getValue1Async(); const p2 = getValue2Async(); const value1 = await p1; const value2 = await p2; // use both values 回答1: TL;DR Don't use the pattern in the question where you get the promises, and then separately wait on them;