Tag: ecmascript 6

angular2 failing lodash import

I started simple Angular 2 app, all working. But when I add import of lodash and try to use it, I get errors and the app stops working, and can’t figure out what is the problem. I am getting these 2 errors in console: Uncaught SyntaxError: Unexpected token <__exec @ system.src.js:1374entry.execute @ system.src.js:3300linkDynamicModule @ system.src.js:2921link […]

ES6 / ECMA6 template literals – not working

I wanted to try using template literals and it’s not working: it’s displaying the literal variable names, instead of the values. I am using Chrome v50.0.2 (and jQuery). Example: console.log(‘categoryName: ${this.categoryName}\ncategoryElements: ${this.categoryElements} ‘); Output: ${this.categoryName} categoryElements: ${this.categoryElements}

ES6 destructuring object assignment function parameter default value

Hi I was going through examples of object destructuring use in passing function parameters here Object Destructuring Demo function drawES6Chart({size = ‘big’, cords = { x: 0, y: 0 }, radius = 25} = **{}**) { console.log(size, cords, radius); // do some chart drawing } // In Firefox, default values for destructuring assignments are not […]

A “map” to only part of the elements in Javascript

Is there a way, in Javascript (ES2015), to map only part of a array? E.g.: let m = someArray.map(function(n){ if(n===0) return n+1; } That’s it, it would return a mapped array that has less elements than the original one. Is that something that we could accomplish out of the box with some functional programming technique?

what happens if we dont resolve or reject the promise

I have a scenario where I am returning a promise. The promise basically give the response of a ajax request. On rejecting the promise it shows an error dialog that there is a server error. What I want to do is when the response code is 401, I neither want to resolve the promise nor […]

import ReactCSSTransitionGroup in ES6 React Javascript

I am using NPM to manage my packages and modules on my node.js app. I have updated react to ^0.14.6 version and also installed ReactCSSTransitionGroups via npm. Unfortunately uppon trying to use this addon in one of my child components I face the following error which says that its still undefined: Uncaught ReferenceError: ReactCSSTransitionGroup is […]

SystemJS import “base script” from directory, like in Python

Is it possible to import a “base script” from a module-like directory with SystemJS, like a Python’s __init__.py? Example: Directory structure app/ module1/ __init__.js // or module1.js module1.weeble.js module1.thingy.js module2/ __init__.js // or module2.js module2.weeble.js module2.thingy.js bootstrap.js module1/__init__.js import Weeble from “./module1.weeble” import Thingy from “./module1.thingy” class Module1 { constructor() { this.weeble = new Weeble(); […]

“Import” ES6 for Node

I want to use import from ES6 rather than require from common.js in Node. For some reason I thought import would work by default in Node. But looks like it does not. Is there some npm package i need to install for that to work?

Get typeof of the value in ES6

I am using ES6 + babel with a plugin of [“iife-wrap”]. I am trying to remake the plugin I create before (form-validation). I am trying to check if the data is an object. For es5 this is just: typeof blah === ‘object’ or string, function, and etc. However if I put it on es6. It […]

How can I detect when a global variable is set in javascript?

In javascript, I can detect when a global variable foo is set (assuming that it is initially undefined) by using Object.defineProperty: var foo_; Object.defineProperty(window, ‘foo’, { get: function() { return foo_; }, set: function(newFoo) { console.log(‘foo set to ‘ + newFoo); foo_ = newFoo; } }); Is there a more elegant way to do this? […]