Skip to content

xgrommx/es6-class-classic

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

es6-class-classic

Compiles JavaScript written using ES6 classes to ES3 syntax. For example, this:

class Hello {
  constructor(name) {
    this.name = name;
  }

  hello() {
    return "Hello " + this.name + "!";
  }
}

class HelloWorld extends Hello {
  constructor() {
    super("World");
  }

  echo() {
    alert(super.hello());
  }
}

var hw = new HelloWorld();
hw.echo();

compiles to this:

var Hello = function() {
  var Hello = function Hello(name) {
    this.name = name;
  };

  Hello.prototype.hello = function hello() {
    return "Hello " + this.name + "!";
  };

  return Hello;
}();

var HelloWorld = function() {
  var HelloWorld = function HelloWorld() {
    Hello.call(this, "World");
  };

  var HelloWorldPrototype = function() {};
  HelloWorldPrototype.prototype = Hello.prototype;
  HelloWorld.prototype = new HelloWorldPrototype();
  HelloWorld.prototype.constructor = HelloWorld;

  HelloWorld.prototype.echo = function echo() {
    alert(Hello.prototype.hello.call(this));
  };

  return HelloWorld;
}();

var hw = new HelloWorld();
hw.echo();

Install

$ npm install es6-class-classic

Browserify

Browserify support is built in.

$ npm install es6-class-classic  # install local dependency
$ browserify -t es6-class-classic $file

Setup

First, install the development dependencies:

$ npm install

Then, try running the tests:

$ npm test

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published