Tag: ecmascript 6

React-router error – 'Cannot call method 'getRouteAtDepth' of undefined'

I am trying to implement react-router on an my app. My main file contains the following code: ‘use strict’; import ‘babel/polyfill’; import React from ‘react/addons’; import App from ‘./components/App’; import ContentPage from ‘./components/ContentPage’; import Dispatcher from ‘./core/Dispatcher’; import AppActions from ‘./actions/AppActions’; import Router from ‘react-router’; var { Route, RouteHandler, Link } = Router; function run() […]

Ecmascript 6 visual studio

I need help how to setup Visual Studio 2013 express, so can work with the new javascript syntax. As I see, the intellisense work very good, but the problem is when I load html page with js code in browser. For example, the code below does not make visible the canvas, problem with LET keyword, […]

How to use “import” in a polymer element

I’m trying something like the following: <dom-module id=”my-app”> <template> <div>{{data.name}}</div> </template> <script> import data from ‘data’; class MyApp { constructor() { … } beforeRegister() { this.is = ‘my-app’; this.properties = { data: { type: Object, value: function () { return data; }, } }; } ready() {} … } </script> </dom-module> So, I have here […]

js generator for asynchronous function

How to use yield in a nested function? function* translate(){ socket.once( ‘translate/set’, function( data){ yield data }); socket.emit( ‘translate/get’, { query: query}) }; var data = translate().next().value; console.log( data); Error yield is not defined I do not understand how to use the generator to an asynchronous function, without changing their code

What's the difference between “super()” and “super(props)” in React when using es6 classes?

When is it important to pass props to super(), and why? class MyComponent extends React.Component { constructor(props) { super(); // or super(props) ? } }

How do I return the response from an asynchronous call?

I have a function foo which makes an Ajax request. How can I return the response from foo? I tried to return the value from the success callback as well as assigning the response to a local variable inside the function and return that one, but none of those ways actually return the response. function […]

Are variables declared with let or const not hoisted in ES6?

I have been playing with ES6 for a while and I noticed that while variables declared with var are hoisted as expected… console.log(typeof name); // undefined var name = “John”; …variables declared with let or const seem to have some problems with hoisting: console.log(typeof name); // ReferenceError let name = “John”; and console.log(typeof name); // […]

Why does the es6 version of my webpack config give me an error, but the es5 version doesn't?

I’m working on bundling a project using webpack, and I’m doing so with this config that is compiled with babel 6 (node 5, npm 3): import webpack from ‘webpack’; export default { entry: ‘./node_modules/graphql/graphql.js’, output: { path: ‘./build’, filename: ‘bundle.js’, libraryTarget: “var”, library: “graphql” }, resolve: { extensions: [”, ‘.js’] }, devtool: ‘eval’ }; However, […]

Uglify bundled JS from Browserify

I have the following modules installed: babelify babel-preset-es2015 browserify uglifyify Now I have a core file server.js which contains ES6 javascript. I can convert the ES6 to ES5 and bundle the code for browsers with the following command: browserify server.js -o ./public/bundle.js -t [ babelify –presets [es2015] ] But now I want to get uglifyify […]

Importing ES6 modules in deep directories

Given this directory tree: components foo index.js bar index.js Using babel es6, I would like to do this: import Foo from “./components/foo” import Bar from “./components/foo/bar” But it errors with Module build failed: Error: ENOENT: no such file or directory, open ‘/Users/jemminger/Development/whatever/components/foo/bar.js’ The only way I can get it to work is this: import Foo […]