ecmascript-7

How to avoid hard coded this? in Decorators

蹲街弑〆低调 提交于 2019-11-29 03:09:54
问题 I have read "How to implement a typescript decorator?" and multiple sources but there is something that i have nor been able to do with decorators. class FooBar { public foo(arg): void { console.log(this); this.bar(arg); } private bar(arg) : void { console.log(this, "bar", arg); } } If we invoke the function foo : var foobar = new FooBar(); foobar.foo("test"); The object FooBar is logged in the console by console.log(this); in foo The string "FooBar {foo: function, bar: function} bar test" is

React with ES7: Uncaught TypeError: Cannot read property 'state' of undefined [duplicate]

自闭症网瘾萝莉.ら 提交于 2019-11-28 19:09:33
This question already has an answer here: Unable to access React instance (this) inside event handler 18 answers I'm getting this error Uncaught TypeError: Cannot read property 'state' of undefined whenever I type anything in the input box of AuthorForm. I'm using React with ES7. The error occurs on 3rd line of setAuthorState function in ManageAuthorPage . Regardless of that line of code even if I put a console.log(this.state.author) in setAuthorState, it will stop at the console.log and call out the error. Can't find similar issue for someone else over the internet. Here is the

ES6 / ES7 support in Visual Studio 2015 Community

本秂侑毒 提交于 2019-11-28 08:09:25
I'm hearing that VS 2015 is supporting the new js syntax but when I open up a project written using aurelia.js in this IDE intellisense complains about many, many things eg. export class UpperValueConverter { toView(value){ return value && value.toUpperCase(); } } I have the WebEssentials 2015 installed. Still nothing seems to work... Probably an important information is that my current VS installation is a fresh one, so I didn't mess up any settings. I was having this problem in .jsx files, visual studio 2015 was using the react-tools plugin to parse and highlight the syntax errors. I can't

How can I `await` on an Rx Observable?

不羁岁月 提交于 2019-11-27 17:47:04
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. You have to pass a promise to await . Convert the observable's next event to a promise and await that. if (condition) {

How to filter Object using Array.prototype.filter?

霸气de小男生 提交于 2019-11-27 15:39:19
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 = arr.filter(String) // [1, 2, true, 4, Object, 6, 7, Object, 9, Array[1]] If we want to filter items

Can I catch an error from async without using await?

梦想与她 提交于 2019-11-27 15:36:54
问题 Can errors from a non-awaited async call be caught, sent to an original encapsulating try/catch, or raise an uncaught exception? Here's an example of what I mean: async function fn1() { console.log('executing fn1'); } async function fn2() { console.log('executing fn2'); throw new Error('from fn2'); } async function test() { try { await fn1(); fn2(); } catch(e) { console.log('caught error inside test:', e); } } test(); In this scenario, the error thrown from fn2 will be swallowed silently, and

Using `window.location.hash.includes` throws “Object doesn't support property or method 'includes'” in IE11

扶醉桌前 提交于 2019-11-27 10:03:07
问题 I am checking the URL to see if it contains or includes a ? in it to control the hash pop state in the window. All other browsers aren’t having an issue, only IE. The debugger gives me this error when I try to load in this way: Object doesn't support property or method ' includes ' I get no error when I load the page in through the popstate. $(document).ready(function(e) { if(window.location.hash) { var hash; if(window.location.hash.includes("?")) { alert('I have a ?'); hash = window.location

ie does not support 'includes' method

爷,独闯天下 提交于 2019-11-27 08:12:19
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 ((row_cells[i]+"").includes("#Eval(" + k + ")")) { cell.Keys.push(new Key(k,v)); ...Code goes on

VSCode Linter ES6 ES7 Babel linter

做~自己de王妃 提交于 2019-11-27 06:30:19
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. Damien Leroux 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, "jquery": true }, "parser": "babel-eslint", "parserOptions": { "ecmaVersion": 6, "sourceType":

ES6 / ES7 support in Visual Studio 2015 Community

杀马特。学长 韩版系。学妹 提交于 2019-11-27 02:05:52
问题 I'm hearing that VS 2015 is supporting the new js syntax but when I open up a project written using aurelia.js in this IDE intellisense complains about many, many things eg. export class UpperValueConverter { toView(value){ return value && value.toUpperCase(); } } I have the WebEssentials 2015 installed. Still nothing seems to work... Probably an important information is that my current VS installation is a fresh one, so I didn't mess up any settings. 回答1: I was having this problem in .jsx