Tag: ecmascript 6

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> […]

ES6, export all imports

This question already has an answer here: ES6 Modules: transitively exporting symbols (i.e., from imported files) 1 answer

Typescript: Inject generic & get ES6 module name

I am trying to build a generic repository using: Typescript ES6 Angular 1.x But I can’t figure out how I should inject the Entity and then get its module name. The reason why i want to get the name: Is because i follow a naming convention where a file called order-count.ts should render the URL […]

Create a class extending from ES6 Map

Trying to get away with custom get/set functionality on ES6 Maps. Currently using Babel to transpile my code to ES5. Chrome Version 41.0.2272.101 m class MyMap extends Map { get(key) { if (!this.has(key)) { throw new Error(…); } return super.get(key); } set(key) { if (this.has(key)) { throw new Error(…); } return super.set(key); } } Not […]