es6-modules

ES6 Modules: Undefined onclick function after import

不问归期 提交于 2019-11-27 17:23:10
问题 I am testing ES6 Modules and want to let the user access some imported functions using onclick : test.html: <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>Module Test</title> </head> <body> <input type="button" value="click me" onclick="hello();"/> <script type="module">import {hello} from "./test.js";</script> </body> </html> test.js: export function hello() {console.log("hello");} When I click the button, the developer console says: ReferenceError: hello is not defined . How

ES6 module Import giving “Uncaught SyntaxError: Unexpected identifier”

非 Y 不嫁゛ 提交于 2019-11-27 13:51:12
For a personal project, I'm trying to use ES6 import to write cleaner code. As first test, I'm writing an object that should generate a menu. The whole code is working when I'm directly loading up the class, yet when using the import and export in ES6, it gives an "Uncaught SyntaxError: Unexpected identifier" error on the import line in main.js I've got the following files: assets/js/menu.module.js 'use strict'; export default class Menu { ... } assets/js/main.js import Menu from "./menu.module.js"; window.addEventListener('DOMContentLoaded', () => { const menu = new Menu(); }); index.html

Javascript ES6 export const vs export let

人盡茶涼 提交于 2019-11-27 10:46:08
Let's say I have a variable that I want to export. What's the difference between export const a = 1; vs export let a = 1; I understand the difference between const and let , but when you export them, what are the differences? In ES6, import s are live read-only views on exported-values. As a result, when you do import a from "somemodule"; , you cannot assign to a no matter how you declare a in the module. However, since imported variables are live views, they do change according to the "raw" exported variable in exports. Consider the following code (borrowed from the reference article below):

How will browsers handle ES6 import/export syntax

落爺英雄遲暮 提交于 2019-11-27 09:17:01
I've been thinking around this question lot of days and i have decided to ask the experts. How browsers will handle the new import/export syntax ? I mean: will the modules be loaded asynchronously ? Referencing only my main or entry file and browsers will lazy load the requiere modules. Maybe am i missing or misunderstanding something about this new architecture ? Thank you very much! Regards. This is standardized now and supported by all major modern browsers. will the modules be loaded asynchronously? Yes, with two options available; details below. Referencing only my main or entry file and

Cypress with SystemJS

风流意气都作罢 提交于 2019-11-27 08:09:32
问题 I am attempting to create some basic tests to try out the new Cypress library. In my test I have cy.visit('http://mywebsite.com'); which is loading an AngularJS app that uses SystemJS. If I understand Cypress correctly, I shouldn't have to do anything else and it will make sure the page is loaded before running anything else. However this doesn't seem to be working because the page is loaded, but SystemJS is still loading the modules. How can I get Cypress to wait for all the SystemJS modules

How to use namespaces with import in TypeScript

拜拜、爱过 提交于 2019-11-27 08:02:14
I have two classes in two separate files and one extends from another. The base class contains some import statements using node modules. It is unclear to me why the derived class (which is in a separate file) does not recognize the base class!!!??? Can someone clarify this please? // UtilBase.ts /// <reference path="../typings/node.d.ts" /> /// <reference path="../typings/packages.d.ts" /> import * as path from "path"; // <---- THIS LINE BREAKS THE BUILD!!!! namespace My.utils { export class UtilBase { protected fixPath(value: string): string { return value.replace('/', path.sep); } } } And

ES6 Destructuring and Module imports

时光怂恿深爱的人放手 提交于 2019-11-27 07:44:40
I was under the impression that this syntax: import Router from 'react-router'; var {Link} = Router; has the same final result as this: import {Link} from 'react-router'; Can someone explain what the difference is? (I originally thought it was a React Router Bug .) Felix Kling import {Link} from 'react-router'; imports a named export from react-router , i.e. something like export const Link = 42; import Router from 'react-router'; const {Link} = Router; pulls out the property Link from the default export , assuming it is an object, e.g. export default { Link: 42 }; (the default export is

Classic scripts v/s module scripts in Javascript

时光毁灭记忆、已成空白 提交于 2019-11-27 06:02:09
问题 I was going through the WHATWG specs for async and defer attributes for the <script> tag, when I saw this statement: Classic scripts may specify defer or async ; module scripts may specify async . I went through the WHATWG definitions for classic and module scripts, but didn't really get much clarity. Could someone explain to me like I'm 5, the differences between classic and module scripts in Javascript? 回答1: A classic script is just a standard JavaScript script as you know it. A module

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

不羁的心 提交于 2019-11-27 02:59:20
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? Why it doesn't work import * as MC from './MyClass'; This is ES6/ES2015-style import syntax. The exact meaning of this is "Take

Wildcard or asterisk (*) vs named or selective import es6 javascript

旧街凉风 提交于 2019-11-27 02:04:17
问题 Just wondering which one is the best way to use import: import * as Foo from './foo'; VS: import { bar, bar2, bar3 } from './foo'; In terms of efficiency, say for example, I'm using webpack for bundling all the JavaScript files. Will the first one actually importing everything even though I'm not using them in the main code? Some references that I can find are: In Airbnb style guide, they are recommending no wildcard so there will always be default import object, and this. 回答1: If you use