Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/nsisodiya/klass
Simple JavaScript Prototype Inheritance & Expressive Classes
https://github.com/nsisodiya/klass
Last synced: about 1 month ago
JSON representation
Simple JavaScript Prototype Inheritance & Expressive Classes
- Host: GitHub
- URL: https://github.com/nsisodiya/klass
- Owner: nsisodiya
- Created: 2014-03-26T11:27:28.000Z (almost 11 years ago)
- Default Branch: master
- Last Pushed: 2014-05-05T05:30:43.000Z (over 10 years ago)
- Last Synced: 2024-11-08T10:17:05.297Z (2 months ago)
- Language: JavaScript
- Size: 145 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
klass
=====Simple JavaScript Prototype Inheritance & Expressive Classes, fully inspired by https://github.com/ded/klass
Example
==========```js
var Person = klass({
initialize: function (full_name, age) {
this.full_name = full_name;
this.age = age;
},
drive: function () {
if (this.age >= 18) {
console.log(this.full_name + " is driving");
} else {
console.log(this.full_name + " is not eligible for driving");
}
return this;
},
eat: function () {
console.log(this.full_name + " is eating");
return this;
}
});var Employee = Person.extend({
initialize: function (full_name, age, job_title) {
this.job_title = job_title;
Employee.parent.call(this, full_name, age);
},
office: function () {
console.log(this.full_name + " is a " + this.job_title + " and he is going to Office");
return this;
}
});var Manager = Employee.extend({
initialize: function (age, full_name, job_title, dept) {
this.dept = dept;
Manager.parent.call(this, full_name, age, job_title);
},
presentation: function () {
console.log(this.full_name + " is a Manager of " + this.dept + " Department and he is doing presentiation");
return this;
}
});var deepak = new Person("Deepak", 17);
deepak.eat().drive();
var narendra = new Employee("Narendra", 30, "Engineer");
narendra.eat().drive().office();
var chetan = new Manager(24, "Chetan", "Doctor", "Research");
chetan.eat().drive().office().presentation();
```demo
======
http://jsfiddle.net/nsisodiya/U6yHL/