Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/marco-ponds/classy.js
A Simple Javascript Inheritance implementation
https://github.com/marco-ponds/classy.js
Last synced: about 1 month ago
JSON representation
A Simple Javascript Inheritance implementation
- Host: GitHub
- URL: https://github.com/marco-ponds/classy.js
- Owner: marco-ponds
- Created: 2015-02-26T10:20:00.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2015-04-27T13:36:37.000Z (over 9 years ago)
- Last Synced: 2024-09-09T09:13:47.458Z (2 months ago)
- Language: JavaScript
- Size: 191 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
##Classy
Classy is a Javascript Inheritance implementation. This is pretty much everything you need to know.
You will gain access to a simple way to implement a Javascript Class in your code along with a useful "include" method.
---
##Example
###Building.js
```javascript
Class( "Building", {
//constructor
Building: function( type ) {this.type = type;
this.floors = 1;
this.collapsed = false;},
//methods
addFloors: function( number ) {this.floors += number;
},
demolish: function() {
this.collapsed = true;
}});
```
###Home.js
```javascript
Class( "Home", {
//constructor
Home: function( type, familyName ) {Building.call( this, type );
this.familyName = familyName;},
//methods
changeName: function( name ) {this.familyName = name;
},
demolish: function() {
//calling super "demolish" method
this._demolish();
alert("Adieu!");
}})._extends( "Building" );
```
Constructor name must be the same of the Class one. Class extension is achieved through the function ```_extends ( "className" )```.
You can see the file "index.html" to see how to work with the include method. Include has a useful feature which allows you to import multiple files at once ( you can specify an array of strings or a single string, and you're free to avoid to insert the ".js" file extension ):```javascript
var toInclude = [ "js/FirstClass.js", "js/SecondClass" ];
//var toInclude = "js/OtherClass.js";include( toInclude, function() {
var first_instance = new FirstClass( params );
});
```
That's all you need to know to get started. And remember, always stay classy.