oopsy v0.2.0
.oooooo.
d8P' `Y8b
888 888 .ooooo. oo.ooooo. .oooo.o oooo ooo
888 888 d88' `88b 888' `88b d88( "8 `88. .8'
888 888 888 888 888 888 `"Y88b. `88..8'
`88b d88' 888 888 888 888 o. )88b `888'
`Y8bood8P' `Y8bod8P' 888bod8P' 8""888P' .8'
888 .o..P'
o888o `Y8P'
Oopsy makes it easier to use the Object-Orientated Programming (OOP) model in JavaScript.
Install
Install using the package manager for your desired environment(s):
$ npm install --save oopsy
# OR:
$ bower install --save skelp-oopsy
You'll need to have at least Node.js installed and you'll only need Bower if
you want to install that way instead of using npm
.
If you want to simply download the file to be used in the browser you can find them below:
API
The API is extremely simple and is designed to make it as easy as possible to implement traditional inheritance.
Oopsy.extend([constructor][, prototype][, statics])
It is very flexible and can be used to extend classes:
var BaseObject = Oopsy.extend(function(options) {
this.options = options || {}
})
var ChildObject = BaseObject.extend({
getOption: function(name) {
return this.options[name]
},
setOption: function(name, value) {
this.options[name] = value
}
})
var Person = ChildObject.extend(function(name, options) {
Person.super_.call(this, options)
this.name = name
Person.people.push(this)
}, {
greet: function(name) {
return 'Hello ' + name + ', my name is ' + this.name
}
}, {
people: []
})
All constructors extended by Oopsy are given a static super_
property which references the super constructor.
Also, this can be used to extend existing classes such as EventEmitter
:
var EventEmitter = require('events').EventEmitter
var Oopsy = require('oopsy')
var BaseObject = Oopsy.extend(function() {
EventEmitter.call(this)
}, EventEmitter.prototype, EventEmitter)
However, this last approach has the caveats of instanceof
not identifying this kind of inheritance and super_
will
only reference the constructor that is extended.
Bugs
If you have any problems with Oopsy or would like to see changes currently in development you can do so here.
Contributors
If you want to contribute, you're a legend! Information on how you can do so can be found in CONTRIBUTING.md. We want your suggestions and pull requests!
A list of Oopsy contributors can be found in AUTHORS.md.
License
See LICENSE.md for more information on our MIT license.
© 2016 Skelp