Posts

Showing posts with the label ecmascript-6

undefined variable that equals to a node module

undefined variable that equals to a node module I try to transpire my file using browserify or webpack. This is my code: let rangy = require('rangy') rangy.init() const rang = () => rangy After transpire my code and add in a html page, I try to get rangy in console, but when i type rangy and press enter button, js says: rangy Uncaught ReferenceError: rangy is not defined When i type rang() and press enter, js says: rang() undefined But line 2 runs correctly. I need to use rangy in script tag of my index.html . rangy index.html How can I do this? This is my transpired file: (function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n...

Arrow function is skipped

Arrow function is skipped I don't see anything wrong with this arrow function but even if I replace position with the number 2, it still doesn't run its internals const isValidMove = (position) => { console.log("a") const valid = !isNaN(+position); return valid; } I don't get anything logged to the console even with this: const isValidMove = (2) => { console.log("a") const valid = !isNaN(+position); return valid; } How are you calling the function? And version 2 is a syntax error. – Chris G Jun 29 at 21:54 Also, which console are you looking at? When I "run" version 2, I get SyntaxError: missing formal parameter – Chris G Jun 29 at 22:00 ...

Arrow function vs function declaration / expressions: Are they equivalent / exchangeable?

Arrow function vs function declaration / expressions: Are they equivalent / exchangeable? Canonical question If you find a question about issues after replacing a function declaration / expression with an arrow function, please close it as duplicate of this one. Arrow functions in ES2015 provide a more concise syntax. Can I replace all my function declarations / expressions with arrow functions now? What do I have to look out for? Examples: Constructor function function User(name) { this.name = name; } // vs const User = name => { this.name = name; }; Prototype methods User.prototype.getName = function() { return this.name; }; // vs User.prototype.getName = () => this.name; Object (literal) methods const obj = { getName: function() { // ... } }; // vs const obj = { getName: () => { // ... } }; Callbacks setTimeout(function() { // ... }, 500); // vs setTimeout(() => { // ... }, 500); Variadic functions function sum() { let args = .slice(arguments...

How to implement private method in ES6 class with Traceur [duplicate]

How to implement private method in ES6 class with Traceur [duplicate] This question already has an answer here: I use Traceur Compiler to have advantage with ES6 features now. I want to implement this stuff from ES5: function Animal() { var self = this, sayHi; sayHi = function() { self.hi(); }; this.hi = function() {/* ... */} } Currently traceur does not support private and public keywords (from harmony). And ES6 class syntax does not allow to use simple var (or let ) statements in class body. private public var let The only way that I am find is to simulate privates before class declaration. Something like: var sayHi = function() { // ... do stuff }; class Animal { ... It is better then nothing but as expected you can not pass correct this to private method without apply -ing or bind -ing it every time. this apply bind So, is there any possibility to use private data in ES6 class compatible with traceur compiler? This question has been asked b...

let statement in loop doesn't work as expected in IE

let statement in loop doesn't work as expected in IE I am trying some example in ECMAScript 6. That is working differently compared to other browsers. This returns true in Firefox, but it returns false in IE. Why is this working different in Internet Explorer? true false let callbacks = for (let i = 0; i <= 2; i++) { callbacks[i] = function () { console.log(i); return i * 2 } } console.log(callbacks[0]() === 0); console.log(callbacks[1]() === 2); console.log(callbacks[2]() === 4); IE doesn't support ES6 fully. – Rajaprabhu Aravindasamy Aug 26 '16 at 6:30 ok.I does not show any errors. But it returns the value wrongly. – Raavanan Aug 26 '16 at 6:31 ...

finding if all items in array are set to expected value in javascript? [on hold]

finding if all items in array are set to expected value in javascript? [on hold] I am fairly new to javascript and I am learnig by doing a project. I have a situtation in which I collect statuses of various tasks to an array. var statuses = ["deployed", "deployed", "pending", "staged"]; var statuses = ["deployed", "deployed", "pending", "staged"]; now I want to call clearInterval(interval) when all the items in the array are deployed clearInterval(interval) array deployed Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question. Please take a few minutes to read through "how to ask a good question...