ecmascript-2017

Testing angular service with $httpBackend with async/await using jasmin

别等时光非礼了梦想. 提交于 2021-02-18 13:47:45
问题 I have previously successfully tested an angular controller that uses ES7 async/await syntax with jasmine - async updateGridAsync() { const paging = angular.copy(this.gridData.getServerCallObj()); } try { const model = await this.service.getAsync(paging); this._$rootScope.$apply(); } catch (e){this._notification.error(this._$rootScope.lang.notifications.unexpectedError); } } it('updateGridAsync() should update the gridData when succeed', async (done) => { expect(ctrl.gridData.totalItems)

How does async-await works in Javascript?

瘦欲@ 提交于 2021-02-16 15:29:09
问题 Does making a function async make it asynchronous? I started using async-await in place of promise chain. I did something like async function f(){ let r = await first(); let d = await sec(r); return d; } On calling this function I was able to see that all code happened asynchronously. But in some older article I read we can't create asynchronous function in javascript. So does making function async makes it asynchronous. 回答1: Does making a function async make it asynchronous? No, it makes it

How does async-await works in Javascript?

泄露秘密 提交于 2021-02-16 15:29:05
问题 Does making a function async make it asynchronous? I started using async-await in place of promise chain. I did something like async function f(){ let r = await first(); let d = await sec(r); return d; } On calling this function I was able to see that all code happened asynchronously. But in some older article I read we can't create asynchronous function in javascript. So does making function async makes it asynchronous. 回答1: Does making a function async make it asynchronous? No, it makes it

Using async/await with a forEach loop

假装没事ソ 提交于 2021-02-11 12:24:29
问题 Are there any issues with using async / await in a forEach loop? I'm trying to loop through an array of files and await on the contents of each file. import fs from 'fs-promise' async function printFiles () { const files = await getFilePaths() // Assume this works fine files.forEach(async (file) => { const contents = await fs.readFile(file, 'utf8') console.log(contents) }) } printFiles() This code does work, but could something go wrong with this? I had someone tell me that you're not

Why is Boolean.prototype a Boolean object again? (And same for String and Number, but not Date or RegExp?)

时光怂恿深爱的人放手 提交于 2021-02-08 05:31:10
问题 In ES5, Boolean.prototype is a Boolean object: The Boolean prototype object is itself a Boolean object (its [[Class]] is "Boolean") whose value is false. In ES6 / ES2015, it isn't: The Boolean prototype object is an ordinary object. It is not a Boolean instance and does not have a [[BooleanData]] internal slot. In ES2016, it is once again: The Boolean prototype is itself a Boolean object; it has a [[BooleanData]] internal slot with the value false. (and it remains so in ES2017 as well.) The

how to reuse es6 class in vue js?

笑着哭i 提交于 2021-02-07 08:16:31
问题 How to reuse some existing ES6 classes in Vue Js. Have a class which has a variable being updated by observable. class A { public a: string; someobservable.subscribe((a) =>{ this.a = a; }) } In vue.JS have created the object of this class. Sample how property is been used: created: { objA = new A(); } methods: { getA() { if(this.objA !== undefined){ return objA.a; } } } and in vue template: <div>{{getA()}}</div> The value in template gets out of sync with value of variable in class. Is there

how to reuse es6 class in vue js?

雨燕双飞 提交于 2021-02-07 08:15:23
问题 How to reuse some existing ES6 classes in Vue Js. Have a class which has a variable being updated by observable. class A { public a: string; someobservable.subscribe((a) =>{ this.a = a; }) } In vue.JS have created the object of this class. Sample how property is been used: created: { objA = new A(); } methods: { getA() { if(this.objA !== undefined){ return objA.a; } } } and in vue template: <div>{{getA()}}</div> The value in template gets out of sync with value of variable in class. Is there

Using async/await with a forEach loop

那年仲夏 提交于 2021-02-05 09:39:39
问题 Are there any issues with using async / await in a forEach loop? I'm trying to loop through an array of files and await on the contents of each file. import fs from 'fs-promise' async function printFiles () { const files = await getFilePaths() // Assume this works fine files.forEach(async (file) => { const contents = await fs.readFile(file, 'utf8') console.log(contents) }) } printFiles() This code does work, but could something go wrong with this? I had someone tell me that you're not

How to get Javascript's IMPORT EXPORT working. Do I need transpiler?

房东的猫 提交于 2021-01-27 21:50:42
问题 I am so confused about this. All I want to do is simply break up my javascript into modules, and include them in certain pages. Some pages may need my user-module.js , some pages may not. I have Googled, read the tutorials, and it's still not working for me. Here is a simple test case: 1. Include my script from my html <script src="../js/login-view-model.js"></script> Now, inside there... 2. TRY to include another module/js file // LoginViewModel // I NEED MY IMPORT HERE import { userService

JavaScript/Angular 1 - Promise.all to async-await

£可爱£侵袭症+ 提交于 2021-01-23 07:47:45
问题 I assign two calls to the web service in two variables in referencesPromise and contactTypesPromise $onInit() (I can create a new method for that, if needed) $onInit() { const referencesPromise = this.ReferenceService.getMultipleReferences(this.AgentReferences) const contactTypesPromise = this.ContactService.getContactTypes() Promise.all([referencesPromise, contactTypesPromise]).then((responses) => { this.references = responses[0] this.contactTypes = responses[1] const stateParams = this.