Get functions (methods) of a class [duplicate]

The members of a class are not enumerable. To get them, you have to use Object.getOwnPropertyNames: var propertyNames = Object.getOwnPropertyNames(Object.getPrototypeOf(foo)); // or var propertyNames = Object.getOwnPropertyNames(Foo.prototype); Of course this won’t get inherited methods. There is no method that can give you all of them. You’d have to traverse the prototype chain and get the properties … Read more

Webpack babel 6 ES6 decorators

This Babel plugin worked for me: https://github.com/loganfsmyth/babel-plugin-transform-decorators-legacy npm i –save-dev babel-plugin-transform-decorators-legacy .babelrc { “presets”: [“es2015”, “stage-0”, “react”], “plugins”: [ [“transform-decorators-legacy”], // … ] } or Webpack { test: /\.jsx?$/, loader: ‘babel’, query: { cacheDirectory: true, plugins: [‘transform-decorators-legacy’ ], presets: [‘es2015’, ‘stage-0’, ‘react’] } } React Native With react-native you must use the babel-preset-react-native-stage-0 plugin instead. … Read more

How to use instanceof in a switch statement

A good option is to use the constructor property of the object: // on reject / failure switch (error.constructor) { case NotAllowedError: return res.send(400); case DatabaseEntryNotFoundError: return res.send(404); default: log(‘Failed to do something async with an unspecified error: ‘, error); return res.send(500); } Notice that the constructor must match exactly with the one that object … Read more

Can you use es6 import alias syntax for React Components?

Your syntax is valid. JSX is syntax sugar for React.createElement(type) so as long as type is a valid React type, it can be used in JSX “tags”. If Button is null, your import is not correct. Maybe Button is a default export from component-library. Try: import {default as StyledButton} from “component-library”; The other possibility is … Read more

What exactly does the anonymous JavaScript function f => f do?

f => f is the identity function. It simply returns the argument that was passed in. This function is often used as a default values for transformation processes, since it doesn’t perform any transformation. Is f => f equivalent to () => {} an empty anonymous function? No. The empty function doesn’t return anything. The … Read more

What happens if you don’t resolve or reject a promise?

A promise is just an object with properties in Javascript. There’s no magic to it. So failing to resolve or reject a promise just fails to ever change the state from “pending” to anything else. This doesn’t cause any fundamental problem in Javascript because a promise is just a regular Javascript object. The promise will … Read more