Last active
August 29, 2015 14:26
-
-
Save amannn/e2dff946b3e8564b4017 to your computer and use it in GitHub Desktop.
Demonstration of new organizational ES6 features.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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