How to enumerate es6 class methods [duplicate]

Object.keys() iterates only enumerable properties of the object. And ES6 methods are not. You could use something like getOwnPropertyNames(). Also methods are defined on prototype of your object so you’d need Object.getPrototypeOf() to get them. Working example: for (let name of Object.getOwnPropertyNames(Object.getPrototypeOf(callbacks))) { let method = callbacks[name]; // Supposedly you’d like to skip constructor if … Read more

Replacing angular with standard web technologies

I’ve been researching in the past 3 weeks and turns out many people are thinking about an alternative after Angular took a drastic change path. Fortunately the upcomming W3C Web Components standard actually has all we need and it works right now with polyfills from the Polymer project. So to answer the question: Angular Directives … Read more

Is there a version of setTimeout that returns an ES6 promise?

In Browsers First of all no – there is no built in for this. Lots of libraries that enhance ES2015 promises like bluebird whip with it. I think the other answer conflates executing the function and a delay, it also creates timeouts that are impossible to cancel. I’d write it simply as: function delay(ms){ var … Read more

How to check if a Map or Set is empty?

You use its size property. Both Maps and Sets have it (here and here). const populatedSet = new Set([‘foo’]); console.log(populatedSet.size); // 1 const populatedMap = new Map([[‘foo’, 1]]); console.log(populatedMap.size); // 1 (Side note: WeakMaps and WeakSets don’t have size or several other features their “strong” counterparts have, in order to keep their implementations, and code … Read more

.filter is not a function [duplicate]

filter is a method on arrays. Since the code you posted contains an object, you’re seeing this error. You may want to apply filter after getting all the values from the object using Object.values, like this: var users = { “1”: { “user_id”: 1, “test”: “”, “user_name”: “potato0”, “isok”: “true” }, “2”: { “user_id”: 2, … Read more

this value in JavaScript anonymous function

Inside of your anonymous function this is the global object. Inside of test, this is the instance of MyObject on which the method was invoked. Whenever you call a function like this: someFunction(); // called function invocation this is always the global object, or undefined in strict mode (unless someFunction was created with bind** — … Read more

ES6 Classes Default Value

If you’re going to use ES6, why not use all of ES6, i.e. default values for parameters and destructuring assignment class myClass { constructor({a=”default a value”, b = ‘default b value’, c=”default c value”} = {a:’default option a’, b:’default option b’, c:’default option c’}) { this.a = a; this.b = b; this.c = c; } … Read more

Given ES2015, dependency injection and library abstraction, what should my ideal module look like in 2016? [closed]

To me, this seems to be one of the biggest unaddressed issues of the JS community. There are no best practices around dependency management and dependency injection around (at least to my knowledge). There is a long discussion on this thread: Do I need dependency injection in NodeJS, or how to deal with …?, but … Read more