ecmascript-7

How can I `await` on an Rx Observable?

心不动则不痛 提交于 2019-11-26 19:13:34
问题 I'd like to be able to await on an observable, e.g. const source = Rx.Observable.create(/* ... */) //... await source; A naive attempt results in the await resolving immediately and not blocking execution Edit: The pseudocode for my full intended usecase is: if (condition) { await observable; } // a bunch of other code I understand that I can move the other code into another separate function and pass it into the subscribe callback, but I'm hoping to be able to avoid that. 回答1: You have to

How to filter Object using Array.prototype.filter?

怎甘沉沦 提交于 2019-11-26 17:18:46
问题 Given var arr = [1,2,true,4,{"abc":123},6,7,{"def":456},9,[10]] we can filter number items within array arr using Number constructor var res = arr.filter(Number); // [1, 2, true, 4, 6, 7, 9, Array[1]] are true and [10] expected in resulting array ? If we substitute false for true at arr var arr = [1,2,false,4,{"abc":123},6,7,{"def":456},9,[10]] var res = arr.filter(Number) // [1, 2, 4, 6, 7, 9, Array[1]] using Array.isArray var res = arr.filter(Array.isArray) // [Array[1]] String var res =

How do I destructure all properties into the current scope/closure in ES2015?

风流意气都作罢 提交于 2019-11-26 15:32:02
I'd like to do something like this: const vegetableColors = {corn: 'yellow', peas: 'green'}; const {*} = vegetableColors; console.log(corn);// yellow console.log(peas);// green I can't seem to find or figure out how to do this but I really thought I had seen it done somewhere before! :P NOTE: I'm using Babel with stage set to 0 ; CONTEXT: I'm trying to be drier in JSX and not reference this.state or this.props everywhere. And also not have to keep adding properties to destructure if the data changes. Bergi I think you're looking for the with statement , it does exactly what you are asking for:

ie does not support 'includes' method

别来无恙 提交于 2019-11-26 13:55:38
问题 I have been working on a project and developing a JavaScript framework. The original code is about 700 lines so I only pasted this line. The includes method doesn't work on Internet Explorer. Is there any solution for this? var row_cells = tbl_row.match(/<td[\s\S]*?<\/td>/g); row.Cells = new Array(); if (onRowBindFuncText != null) { /*Fonksyon tanımlanmaışsa daha hızlı çalış*/ var cellCount = 0; for (i = 0; i < row_cells.length; i++) { var cell = new Cell(); $.each(this, function (k, v) { if

VSCode Linter ES6 ES7 Babel linter

萝らか妹 提交于 2019-11-26 12:02:32
问题 How to use Visual Studio code to lint JavaScript file based on babel/ES7 stage-0 rules? I only need to lint code. I already have webpack transpiling Js file. 回答1: How I proceed: install globally eslint : npm install -g eslint install babel-eslint : npm install --save-dev babel-eslint install eslint-plugin-react : npm install --save-dev eslint-plugin-react create .eslintrc file in you root directory. here is my config: { "env": { "browser": true, "node": true, "es6": true, "jest": true,

Can I fire and forget a promise in nodejs (ES7)?

邮差的信 提交于 2019-11-26 08:59:29
I would like to run this code with babel: redisClientAsync.delAsync('key'); return await someOtherAsyncFunction(); inside an async function without await the first line. is this OK? how else can I run something that I don't care? Can I just fire the non-promisified function del('key',null) without a callback? Bergi Yes, you can do that, and it will run the two asynchronous functions in parallel. You've just created a promise and thrown it away. However, this means that when the promise is rejected you won't notice. You'll just get an unhandledRejection eventually . Is this OK? How can I run

Array.prototype.includes vs. Array.prototype.indexOf

北战南征 提交于 2019-11-26 08:04:01
问题 Beyond the improved readability, is there any advantage to includes over indexOf ? They seem identical to me. What is the difference between this var x = [1,2,3].indexOf(1) > -1; //true And this? var y = [1,2,3].includes(1); //true 回答1: tl;dr: NaN is treated differently: [NaN].indexOf(NaN) > -1 is false [NaN].includes(NaN) is true From the proposal: Motivation When using ECMAScript arrays, it is commonly desired to determine if the array includes an element. The prevailing pattern for this is

How can I clone a JavaScript object except for one key?

大兔子大兔子 提交于 2019-11-26 07:56:09
问题 I have a flat JS object: {a: 1, b: 2, c: 3, ..., z:26} I want to clone the object except for one element: {a: 1, c: 3, ..., z:26} What\'s the easiest way to do this (preferring to use es6/7 if possible)? 回答1: If you use Babel you can use the following syntax to copy property b from x into variable b and then copy rest of properties into variable y : let x = {a: 1, b: 2, c: 3, z:26}; let {b, ...y} = x; and it will be transpiled into: "use strict"; function _objectWithoutProperties(obj, keys) {

Can I fire and forget a promise in nodejs (ES7)?

这一生的挚爱 提交于 2019-11-26 01:40:15
问题 I would like to run this code with babel: redisClientAsync.delAsync(\'key\'); return await someOtherAsyncFunction(); inside an async function without await the first line. is this OK? how else can I run something that I don\'t care? Can I just fire the non-promisified function del(\'key\',null) without a callback? 回答1: Yes, you can do that, and it will run the two asynchronous functions in parallel. You've just created a promise and thrown it away. However, this means that when the promise is