Debugging with webpack, ES6 and Babel

This is an issue with Javascript source maps, which don’t currently support mapping symbol names, and babel, which changes the names of import-ed modules when compiling to CommonJS from ES2105 module syntax. Babel does this to fully support the fact that ES2015 modules export bindings by resolving all references to imports whenever they are used … Read more

Return multiple values from ES6 map() function

With using only one reduce() you can do this. you don’t need map(). better approach is this: const values = [1,2,3,4]; const newValues= values.reduce((acc, cur) => { return acc.concat([cur*cur , cur*cur*cur, cur+1]); // or acc.push([cur*cur , cur*cur*cur, cur+1]); return acc; }, []); console.log(‘newValues=”, newValues) EDIT: The better approach is just using a flatMap (as @ori-drori … Read more

What is the difference between Reflect.ownKeys(obj) and Object.keys(obj)?

Object.keys() returns an array of strings, which are the object’s own enumerable properties. Reflect.ownKeys(obj) returns the equivalent of: Object.getOwnPropertyNames(target). concat(Object.getOwnPropertySymbols(target)) The Object.getOwnPropertyNames() method returns an array of all properties (enumerable or not) found directly upon a given object. The Object.getOwnPropertySymbols() method returns an array of all symbol properties found directly upon a given object. var … Read more

React.js: Set a Default value into a prop

I believe that defaultProps should do what you need: import PropTypes from ‘prop-types’; class AppButton extends Component { render(){ return ( <button onClick={this.props.onClick}>{this.props.message}</button> ) } }; AppButton.propTypes = { message: PropTypes.string, onClick: PropTypes.func }; AppButton.defaultProps = { message: ‘Hello’, onClick: function(){ alert(“Hello”); } }; From the docs: The defaultProps will be used to ensure that … Read more

How and why would I write a class that extends null?

EDIT (2021): TC39, which specifies JavaScript still hasn’t resolved exactly how this is supposed to work. That needs to happen before browsers can consistently implement it. You can follow the latest efforts here. Original answer: Instantiating such classes is meant to work; Chrome and Firefox just have bugs. Here’s Chrome’s, here’s Firefox’s. It works fine … Read more