Tag: ecmascript 6

What is the difference between qualified and unqualified imports in the new javascript ES6 module lingo?

I came across this distinction which wasn’t explained well in ExploringJS Qualified and unqualified imports work the same way (they are both indirections) What is the distinction and therefore what does this statement mean?

Why is a string template faster when it is formatted a certain way?

Why is this formatted string template var test = `Today is $ { now }.`; faster than just a regular string template on 1 line like var test = `Today is ${now}.`; You can see the benchmark in the JsPerf test linked below. Also why does Firefox perform way better than Chrome on this benchmark? […]

How to keep injected dependencies private in AngularJS Controllers with ES6 Class

I know that my question is related to this post, but I wonder if there is an AngularJS specific way to address this issue. Here is the deal: I’m using ES6 Class and ControllerAs in my Angular directives, so controllers are declared like so: class myCtrl { constructor ( $log ) { ‘ngInject’; // Dependency […]

`if __name__ == '__main__'` equivalent in javascript es6 modules

Is it possible to check if JavaScript file is being run directly or if it was required as part of an es6 module import. for example a main script is included. // main.js import ‘./other’; if (mainTest){ console.log(‘This should run’); } which imports a dependency. // other.js if (mainTest){ console.log(‘This should never run’); } including […]

EsLint from Visual Studio – Unable to use static props on javascript files

Node Modules: EsLint 1.10.3 Babel-EsLint 4.1.6 Eslint-plugin-react 3.15.0 Sample file being linted: class NotepadComponent extends React.Component { static displayName = ‘NotepadComponent’ static defaultProps = { activeTab: ‘type’ } } Under the command line I can lint and transpile using babel without any issues. The problem is trying to lint from visual studio. I’m using the […]

How can I construct a Template String from a regular string?

This question already has an answer here: Convert a string to a template string 13 answers

Is there an elegant way to tell eslint to ensure that we're not using any ES6 syntax / functions?

Is there an elegant way to tell ESLint to ensure that we’re not using any ES6 / EMCAScript 2015 syntax / functions? I’ve found the following answer somewhat helpful but it seems that it doesn’t take care of everything (e.g. I don’t see how to catch the usage of Object.assign()): How to disable usage of […]

Istanbul with Node.js v6 destructured default parameter values

EDIT Updated example since I copied the wrong one EDIT 2 Apparently, it is a bug with Istanbul itself, see https://github.com/gotwarlost/istanbul/issues/613 I am trying to use Mocha and Istanbul for code coverage in my Node v6 project, where I am using a lot of ES6 features already. I have set up a watcher with Mocha, […]

ES6 and sequelize-cli

My question is how to run sequelize migrations/seeds that written in ES6 ? I tried with babel-node, but getting weird error Command node_modules/babel-cli/lib/babel-node.js node_modules/sequelize-cli/bin/sequelize db:seed Error node_modules/babel-cli/lib/babel-node.js: line 1: /Applications: is a directory node_modules/babel-cli/lib/babel-node.js: line 3: /Applications: is a directory node_modules/babel-cli/lib/babel-node.js: line 4: command not found node_modules/babel-cli/lib/babel-node.js: line 5: syntax error near unexpected token […]

Emulate Slack team model in MongoDB/MongooseJS

I want to make a data model and schemas that look similar to Slack’s Team settings (https://get.slack.help/hc/en-us/articles/201314026-Roles-and-permissions-in-Slack), where there are several roles a user can have, each level with higher permissions. In turn each role can perform certain actions with the highest level being able to do all and the lowest role having minimal, read-only […]