Skip to content

Instantly share code, notes, and snippets.

@amannn
Last active August 29, 2015 14:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amannn/e2dff946b3e8564b4017 to your computer and use it in GitHub Desktop.
Save amannn/e2dff946b3e8564b4017 to your computer and use it in GitHub Desktop.
Demonstration of new organizational ES6 features.
/**
* Import modules from other files.
*
* This example assumes that Shape.js lies in the same directory as this file.
*/
import Shape from './Shape';
/**
* Native classes which can inherit from other classes.
*/
class Rectangle extends Shape {
/**
* Static methods.
*/
static getName() {
return 'Rectangle';
}
/**
* Class properties.
*/
_width = undefined;
_height = undefined;
/**
* Constructor with default parameters.
*/
constructor(x = 0, y = 0, _width = 10, _height = 10) {
super(x, y);
// …
this.render();
}
/**
* Class methods.
*/
render() {
// …
}
/**
* Getters and setters.
*/
get width() { return this._width; }
set width(val) { this._width = val; }
}
/**
* Export modules for usage in other files.
*
* This could also precede the class definition like so:
* export default class Rectangle { … }
*/
export default Rectangle;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment