ecmascript-6

Why not have `import module-name.export1` in javascript?

。_饼干妹妹 提交于 2021-02-08 12:11:17
问题 What is the design limitation behind the ES6 import statement syntax? import { export1 } from "module-name"; as shown here. Why not have import module-name.export1 If somehow having the 'import' keyword in the first place is so important, why not use it like that? For comparison consider several other popular languages: Java : import package.subpackage.ClassName; Python : from module import SomeClass C#: using System.Text; From left to right: broadScope -> module -> particularItem . While in

p5.js && ecmascript6 notation

别来无恙 提交于 2021-02-08 11:18:41
问题 I want use p5.js function inside a class with ECMAScript notation. How to fix this code? class Sketch { constructor(p, params) { // generate vars use in class with object if (typeof params !== 'undefined') { for (let key in params) this[key] = params[key]; } // p5.js object this.p = p; } // p5.js setup method setup() { this.p.createCanvas(); } // p5.js draw method draw() { } } sketch = new Sketch(p5,{}); Error: this.p.createCanvas is not a function 回答1: The docs say that you must instantiate

Converting Javascript 'namespaces' over multiple ES modules

大憨熊 提交于 2021-02-08 10:36:06
问题 In some older codes I 'namespaced' shared methods like this (assuming mycomp is a company name): //File mycomp-common.js var mycomp = window.mycomp || {}; mycomp.common = { //shared methods and constants someMethod: function() { ... } }; //File mycomp-myapp-common.js var mycomp = window.mycomp || {}; mycomp.myapp = mycomp.myapp || {}; mycomp.myapp.common = { //shared methods and constants for myapp someOtherMethod: function() { ... } }; As you can see both files make sure that the main

JavaScript prompt() command

寵の児 提交于 2021-02-08 10:12:54
问题 I just learned about the prompt() command; I know that the prompt() command returns user input in the form of a string. I was messing with the program below, and I typed in Per "Dead" Ohlin for the male name. Why did this work and not cause any problems? "Per "Dead" Ohlin..." should have caused a problem. Does the interpreter automatically fix this by putting an escape character before the quotation marks? let nameOfTheKiller = prompt("Type in a male name."); let nameOfTheVictim = prompt(

Javascript map iterating over multiple items from the same array per loop

烈酒焚心 提交于 2021-02-08 10:12:20
问题 Typescript also works Lets say I have an array like this const array = ['one', 'two', 'three', 'four', 'five'] And I want to produce some components that would look like <div> one two </div> <div> three four </div> <div> five </div> If I wanted to use the map function, to the best of my knowledge I would have to write something like { let saved array.map((item) => { if (saved === ''){ let temp = saved saved = '' return ( <div>{`${item} ${temp}`}</div> ) }else{ saved = item } }) } But I would

JavaScript: Understanding let scope inside for loop [duplicate]

我只是一个虾纸丫 提交于 2021-02-08 09:52:40
问题 This question already has answers here : Explanation of `let` and block scoping with for loops (3 answers) Closed last year . Please consider snippet below- for(let i = 1; i <= 5; i++) { setTimeout(function(){ console.log(i); },100); } In this case, logs inside setTimeout will contain values of variable i as per each iteration of the for loop, i.e the logs will be as follow 1 2 3 4 5 For this, I have read explanations over the Internet like - let creates a variable declaration for each loop

React props/state not passing to modal window

烂漫一生 提交于 2021-02-08 09:39:20
问题 my first ever StackOverflow question, having been banging my head for about 4 hours! I am building a react page that has an image gallery section. On the desktop site, when the user clicks on an image, it launches a Bootstrap modal pop up that should show the details of the clicked painting (title, size, type and media) and a larger image. I have got the modal working (without needing any special library like react-bootstrap) but whichever image is clicked, the modal only shows the image and

Await nothing? Using an empty await to break up a large synchronous function

陌路散爱 提交于 2021-02-08 08:52:31
问题 I have a rather simple question that I can't find an answer to. I have an async function called foo that never awaits, so it's run synchronously. In foo is a long-running loop and it pushes a lot of data into a intermediary buffer. There is an async operation using RxJS that will pull and process data from that buffer, but it won't execute until my long running loop yields somehow, or when the loop is completely done pushing millions of data points into the intermediary buffer (not good). Can

Import with 'require' cannot be used when targeting ECMAScript 6 or higher

折月煮酒 提交于 2021-02-08 08:52:06
问题 In VS2019 16.2.1, I created a new project using the Basic Azure Node.js Express 4 Application with TypeScript Template. I can build and run the application. However, in app.ts, if I hover over the line import debug = require('debug'); I see a tooltip Import with 'require' cannot be used when targeting ECMAScript 6 or higher Here is tsconfig.json "compilerOptions": { "module": "commonjs", "target": "es6", "lib": ["es6"], "sourceMap": true }, "exclude": [ "node_modules" ] } Why do I see this

Use of array.map and onchange in React

陌路散爱 提交于 2021-02-08 07:43:29
问题 The code below contains an array.map function what is the function of term and i and where was it gotten from, and what does the array.map and the onchange do import React, { Component } from 'react'; class Apps extends Component { componentDidMount() { } iLikeFunctions() { console.log('yay functions'); } render() { var array = ['here','we','go']; var no = 'yes'; const display = 'My Name'; return ( <div> <p>{display}</p> <hr /> <input type="text" onChange={this.iLikeFunctions} /> <table>