Node.js library to transform modules into classes
JavaScript
Switch branches/tags
Nothing to show
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
test added test for multiple instances Apr 14, 2013
.gitignore Initial commit Apr 14, 2013
Makefile Initial commit Apr 14, 2013
README.md Update README.md Apr 14, 2013
index.js Initial commit Apr 14, 2013
package.json added to npm Apr 14, 2013

README.md

node-oop-module

Node.js library to transform modules into classes. ##Instalation

npm install oop-module

##Usage ###Class definition You can define classes just like you are define modules.

//Person.js

var firstName;
var lastName;

exports.constructor = function(_firstName, _lastName) {
	firstName = _firstName;
	lastName = _lastName
}
exports.introduce = function() {
	return 'My name is ' + firstName + ' ' + lastName;
}
var oop = require('module-oop');
var Person = oop.class('./Person.js');

var spiderman = new Person('Peter', 'Parker');
var batman = new Person('Bruce', 'Wayne');

assert.notEqual(spiderman, batman);

spiderman.introduce(); //'My name is Peter Parker';
batman.introduce(); //'My name is Bruce Wayne';

###Inheritance Constructor is inherited from class Person. Method introduce is overridden.

//Rapper.js

var oop = require('module-oop');
var _super = oop.extends('./Person.js');

exports.introduce = function() {
	return "YO! " + _super.introduce();
}
var oop = require('module-oop');
var Rapper = oop.class('./Rapper.js');

var snoopDogg = new Rapper('Snoop', 'Dogg');
snoopDogg.introduce(); //'YO! My name is Snoop Dogg';

##Test

make test