Tag: ecmascript 6

Defining and registering Angular directives in a 1.x ES6 project

I have been working on an Angular project that uses all ES6 syntax with babel-node doing the transpiling. This works nicely for controllers and services, but I’m uncertain how best to write directives for the project. According to posts such as this: Using ES6 Classes as Angular 1.x directives writing directives using the ES6 class […]

TypeScript | Socket.IO : How to refer to the client object

I’m testing things with TypeScript,socket.io and the game engine Phaser and working on Visual Studio Here is a sample of my socket.io events handling class class RemoteEventHandlers{ … constructor(socket,players){ this.socket = socket; this.players = players; } … onSocketConnection(client): void{ client.on(‘disconnect’, this.onClientDisconnect.bind(this)); client.on(‘new player’, this.onNewPlayer.bind(this)); client.on(‘move player’, this.onMovePlayer.bind(this)); } onClientDisconnect(): void{ let disconnectedPlayer = this.searchPlayerById(this.id); if […]

ECMA 6 Not working although experimental js is enabled

First of all… excuse my bad english. I have the latest Chrome version, with the Experimental Javascript flag enabled. I want to use ECMA6, but it doesn’t work. I don’t know why. Is there any trick or other flag that must be enabled too? Every reserved word of ECMA6 (like import, class, or whatever) throws […]

Convert javascript class instance to plain object preserving methods

I want to convert an instance class to plain object, without losing methods and/or inherited properties. So for example: class Human { height: number; weight: number; constructor() { this.height = 180; this.weight = 180; } getWeight() { return this.weight; } // I want this function to convert the child instance // accordingly toJSON() { // […]

Automatically export everything from ES5 file to be used in ES6

I have pretty straightforward ES6 code (init.js): import App from ‘../vendor/app’; window.init = function() { let app = new App(); app.hello(); // prints “hello” to console } app module (app.js) is ES5 one and I don’t want to modify this file: function App() { } App.prototype.hello = function() { console.log(‘hello from vendor module’); } The […]

Interrupting a looping WebWorker

I have a Dedicated Webworker that upon receiving a starting signal goes into a long loop and based on some startup settings the loop would “yield” at given points of execution. This is a simplified version of my code var mode = null; var generator = null; function* loop() { for(var i=0;i<10000;i++) { //Do stuff […]

spying on/mocking super class methods in es6

The below are examples but get at the gist of my problem … super class: class Parent { constructor(a) { this._a = a; } doSomething() { … implementation… } } child-class: class Child extends Parent { constructor() { super(‘a’); } doSomethingElse() { return super.doSomething(); } } I am using these classes in Angular, so the […]

ECMAscript 6 code not working

I’m new here. I’m reading a book called ‘ Learning Javascript , 3rd edition ‘ and one of the exercises was running this code: : “use strict”; let sentences = [ { subject: ‘JavaScript’, verb: ‘is’, object: ‘great’ }, { subject: ‘Elephants’, verb: ‘are’, object: ‘large’ }, ]; function say( {subject, verb, object} ) { […]

Angular component syntax, callback function called with wrong context

I’m working on an angular app using the NG6-Starter boilerplate. Now, i’ve got one component with another component inside it, and i’m sending a callback function to the inner component via an attribute. This is how i’m initializing the inner component: <div> <location-form location=’vm.location’ submit-callback=’vm.addLocation’> </location-form> </div> The addLocation function on the parent controller gets […]

How can I declare a public function in an ES6 class?

I’m trying to add a public function inside a React ES6 class extended React.Component. However, nothing I’ve tried makes the function publicly available to other components. Any tips are welcome. Here’s some examples of what I’ve tried: import React, { PropTypes } from ‘react’ import ChildComponent from ‘./ChildComponent’ export class ArticleModal extends React.Component<void, Props, void> […]