es6-modules

Not recommended to use “use strict” in ES6?

♀尐吖头ヾ 提交于 2019-11-26 12:20:15
问题 I\'m not familiar with ECMAScript 6 yet. I\'ve just cloned the React Starter Kit repo, which uses ES6 for application code. I was surprised to see that the linter is configured to forbid occurences of the use strict directive, which I thought was recommended in pre-ES6 JavaScript. So what\'s the point? 回答1: ES6 modules are always in strict mode. To quote the relevant part of the spec: 10.2.1 Strict Mode Code An ECMAScript Script syntactic unit may be processed using either unrestricted or

What does “… resolves to a non-module entity and cannot be imported using this construct” mean?

江枫思渺然 提交于 2019-11-26 10:19:41
问题 I have some TypeScript files: MyClass.ts class MyClass { constructor() { } } export = MyClass; MyFunc.ts function fn() { return 0; } export = fn; MyConsumer.ts import * as MC from \'./MyClass\'; import * as fn from \'./MyFunc\'; fn(); This gives me errors when trying to use new Module \"MyClass\" resolves to a non-module entity and cannot be imported using this construct. and when trying to call fn() Cannot invoke an expression whose type lacks a call signature. What gives? 回答1: Why it doesn

ES2015 “import” not working in node v6.0.0 with with --harmony_modules option

扶醉桌前 提交于 2019-11-26 09:26:37
问题 I am using node v6.0.0 and wanted to use ES2016 (ES6). However I realized that the \"import\" syntax is not working. Isn\'t \"import\" fundamental to for writing modular code in ES2015? I tried running node with --harmony_modules option as well but still got the same error about \"import\". Here\'s the code. Working code without \"import\": \'use strict\'; let sum = 0; class Number { addNumber(num1, num2) { return num1 + num2; } } let numberObj = new Number(); sum = numberObj.addNumber(1,2);

Are ES6 module imports hoisted?

北慕城南 提交于 2019-11-26 09:10:24
问题 I know that in the new ES6 module syntax, the JavaScript engine will not have to evaluate the code to know about all the imports/exports, it will only parse it and “know” what to load. This sounds like hoisting. Are the ES6 modules hoisted? And if so, will they all be loaded before running the code? Is this code possible? import myFunc1 from \'externalModule1\'; myFunc2(); if (Math.random()>0.5) { import myFunc2 from \'externalModule2\'; } 回答1: It will be a SyntaxError . According to this

What is difference between Axios and Fetch?

不想你离开。 提交于 2019-11-26 04:36:01
问题 I am calling the web service by using fetch but the same I can do with the help of axios. So now I am confused. Should I go for either axios or fetch? 回答1: Fetch and Axios are very similar in functionality, but for more backwards compatibility Axios seems to work better (fetch doesn't work in IE 11 for example, check this post) Also, if you work with JSON requests, the following are some differences I stumbled upon with. Fetch JSON post request let url = 'https://someurl.com'; let options = {

ES6 in the browser: Uncaught SyntaxError: Unexpected token import

牧云@^-^@ 提交于 2019-11-26 04:24:47
问题 I\'m new to ES6 (ECMAScript 6), and I\'d like to use its module system in the browser. I read ES6 is supported by Firefox and Chrome, but I\'m getting the following error using export Uncaught SyntaxError: Unexpected token import I have a test.html file <html> <script src=\"test.js\"></script> <body> </body> </html> and a test.js file \'use strict\'; class Test { static hello() { console.log(\"hello world\"); } } export Test; Why? 回答1: Many modern browsers now support ES6 modules. As long as

Which browsers support import and export syntax for ECMAScript 6?

删除回忆录丶 提交于 2019-11-26 03:42:00
问题 I am currently writing a web application using the MEAN Stack, and am attempting to write code in ECMAScript 6 JavaScript; however, I am getting errors in both Chrome and Firefox when using import and export syntax. Are there currently any browsers that fully support ECMAScript 6? Please note: I am not asking when ECMAScript 6 will be supported by browsers. I\'m asking which browsers support ECMAScript 6 import and export syntax. See https://developer.mozilla.org/en-US/docs/Web/JavaScript/New

using brackets with javascript import syntax

孤街醉人 提交于 2019-11-26 01:29:01
问题 I came across a javascript library that uses the following syntax to import libraries: import React, { Component, PropTypes } from \'react\'; What is the difference between the above method and the following? import React, Component, PropTypes from \'react\'; 回答1: import React, { Component, PropTypes } from 'react'; This says: Import the default export from 'react' under the name React and import the named exports Component and PropTypes under the same names. This combines the two common

NodeJS plans to support import/export es6 (es2015) modules

放肆的年华 提交于 2019-11-26 00:15:25
问题 I\'ve been looking all over the internet without a clear answer for this. Currently NodeJS uses only CommonJS syntax to load modules, and if you really want to use the standard ES2015 modules syntax, you either have to transpile it beforehand or use an external module loader at runtime. Currently I\'m not too positive to use either of those two methods, are the NodeJS maintainers even planning to support ES2015 modules or not? I haven\'t found an hint at all about this. At the moment NodeJS 6

`export const` vs. `export default` in ES6

隐身守侯 提交于 2019-11-25 23:29:41
问题 I am trying to determine if there is any big differences between these two, other than being able to import with export default by just doing: import myItem from \'myItem\'; And using export const I can do: import { myItem } from \'myItem\'; I am wondering if there are any differences and/or use cases other than this. 回答1: It's a named export vs a default export. export const is a named export that exports a const declaration or declarations. To emphasize: what matters here is the export