https://github.com/alphahydrae/clah
Simple Javascript Inheritance (by John Resig) with bound callbacks.
https://github.com/alphahydrae/clah
Last synced: about 1 year ago
JSON representation
Simple Javascript Inheritance (by John Resig) with bound callbacks.
- Host: GitHub
- URL: https://github.com/alphahydrae/clah
- Owner: AlphaHydrae
- Created: 2012-08-19T15:10:40.000Z (almost 14 years ago)
- Default Branch: master
- Last Pushed: 2018-09-07T06:58:52.000Z (almost 8 years ago)
- Last Synced: 2024-08-10T07:02:21.577Z (almost 2 years ago)
- Language: JavaScript
- Homepage:
- Size: 18.6 KB
- Stars: 2
- Watchers: 2
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# clah
**Simple JavaScript Inheritance with bound callbacks**
All credit for the inheritance system goes to John Resig. I adapted it to work both with [Node.js](http://nodejs.org) or in a browser, and added a function to generate bound callbacks.
```js
// define a class
var Person = Class.extend({
// this is the constructor
init : function(name) {
this.name = name;
},
// you can use instance properties in your methods
hello : function() {
console.log("Hello, I'm " + this.name + "!");
}
});
// define a subclass
var Pirate = Person.extend({
// you can override methods
hello : function() {
console.log("Ahoy! Me be " + this.name + ".");
}
});
new Person('Jim').hello(); // #=> "Hello, I'm Jim!"
new Pirate('John').hello(); // #=> "Ahoy! Me be John."
// create a bound callback
var jane = new Person('Jane');
var callback = jane.callback('hello');
// you can use this callback anywhere, it will always be bound to the instance
callback(); // #=> "Hello, I'm Jane!"
```
Clah is tested with [Jasmine](https://jasmine.github.io/) and [Travis CI](http://travis-ci.org).
* master [](http://travis-ci.org/AlphaHydrae/clah)
* develop [](http://travis-ci.org/AlphaHydrae/clah)
## Installation
With [NPM](https://npmjs.org):
npm install clah
In a browser:
Download: [Production (minified)](https://raw.github.com/AlphaHydrae/clah/master/lib/class.min.js), [Development (uncompressed)](https://raw.github.com/AlphaHydrae/clah/master/lib/class.js).
[Original Blog Post](http://ejohn.org/blog/simple-javascript-inheritance/)