es6-modules

Javascript ES6 export const vs export let

与世无争的帅哥 提交于 2019-12-17 10:15:14
问题 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? 回答1: 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

How to use namespaces with import in TypeScript

风格不统一 提交于 2019-12-17 09:36:43
问题 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

Destructuring a default export object

≯℡__Kan透↙ 提交于 2019-12-17 09:29:10
问题 Can I destructure a default export object on import? Given the following export syntax ( export default ) const foo = ... function bar() { ... } export default { foo, bar }; is the following import syntax valid JS? import { foo, bar } from './export-file'; I ask because it DOES work on my system, but I've been told it should NOT work according to the spec. 回答1: Can I destructure a default export object on import? No. You can only destructure an object after importing it into a variable.

Is using an ES6 import to load specific names faster than importing a namespace?

故事扮演 提交于 2019-12-17 05:12:35
问题 I've found at least two ways to import functions in from a module like Ramda for example. There are probably a few more ways to do something very similar like const R = require('ramda'); Option 1 is to import certain functions: import { cond, T, always, curry, compose } from 'ramda'; Option 2 is to import the whole module like: import * as R from "ramda"; I would prefer to reference the module from which the function is being called like so: R.T(); But if the 2nd option is used, does it bring

Vuejs 2 impossible to interpolate attribute values

早过忘川 提交于 2019-12-14 00:13:37
问题 <th :class="{'c-' + column, active: sortKey == column}" v-for="column in getColumns()" @click="sortBy(column)"> {{ column }} </th> I get invalid expression: Unexpected token + in but the syntax is supposed to be correct. I tried like 20 other ways and everyone fails Even if I put only column in there i get [Object object] instead of the actual column name so, this doesn't work at all inside es6 template syntax. It only works if I put the templates inside <script> tags in the index.html file

ES6 modules' path resolution failure

你说的曾经没有我的故事 提交于 2019-12-13 18:12:14
问题 I am trying to use the new ES6 features in Chrome 60 (by enabling Experimental Web Platform). This is the structure of my project: myproject ├── src | ├── mymodule.js | ├── dep1.js | ├── dep2.js | ├── dep3.js ├── pages ├── example ├── example1.html This is my page example1.html : <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>E6 6 experiments</title> <script type="module" src="../../src/mymodule.js"></script> </head> <body> </body> </html> I set up Http-Server: http-server /Users

why to import React

╄→尐↘猪︶ㄣ 提交于 2019-12-13 12:25:01
问题 I have code which works only after importing React but I'm not using React anywhere I'm using reactDom instead import ReactDOM from 'react-dom' import React, {Component} from 'react' class App extends Component { render () { return ( <div>comp </div> ) } } //ReactDOM.render(<App/>, document.getElementById('root')) ReactDOM.render(<div>sv</div>, document.getElementById('root')) why its require to import React ?? 回答1: Although you don't explicitly use the React instance you've imported, JSX is

how to get `jQuery` as a function (not as a Module symbol) after ES6 style `import * as jQuery from “./js/jquery.js”;`

梦想的初衷 提交于 2019-12-13 11:27:43
问题 I'm experimenting with native ES6 modules support in Chrome. jQuery is not es6 module (no export) - I know. Still, trying to understand what does it mean for us. This works without errors: <script type="module"> import * as jQuery from "./js/jquery.js"; window.console.log(jQuery); </script> But of course jQuery thereis not a function but a Module symbol. The question is: is it possible to extract jQuery/$ function from jQuery module? When there are no exports defined on module? So do we have

Using Jest to mock named imports

ぐ巨炮叔叔 提交于 2019-12-12 20:50:02
问题 I have a 'notifications.js' module that looks a bit like this: import { Notifications, Permissions } from 'expo' export function setLocalNotification(storage = AsyncStorage) { return storage .getItem(NOTIFICATION_KEY) .then(JSON.parse) .then(data => { if (data === null) { return Permissions.askAsync( Permissions.NOTIFICATIONS ).then(({ status }) => { if (status === 'granted') { Notifications.cancelAllScheduledNotificationsAsync() ...etc. In my test, I want to mock Permissions and

How to retrieve the key into a Semantic-ui-react dropdown?

。_饼干妹妹 提交于 2019-12-12 20:03:11
问题 I have small question about react dropdown menus. I can extract the values inside the dropdown, but I also need the key, because my page is for selling stuff. So, it is an associative table and I need the id from each table to make my query INNERJOIN . This is how I fill it: let options_customers = []; serviceList[0].map((service, i) => options_customers.push({ key: service.Id, text: service.Name, value: service.Name })) My dropdown: <Dropdown selection options={options_customers} onChange=