PseudoClass
An OOP framework for Node.js and the browser
Sweet syntactic sugar for prototypal inheritance.
PseudoClass provides construct()
, destruct()
, _super()
, and an init()
method that runs after construction is complete.
All the same under the hood.
PseudoClass uses JavaScript constructors and prototypal inheritance under the hood. Monkey-patching, instanceof
, and instance.constructor
all work as expected.
Not afraid to mix it up.
Mixins can be added when a class is declared using the mixins
option or after instantiation with the instance.mixin()
method.
Crushes boilerplate with a classy touch.
Stay classy and boilerplate-free with string-based toString
declarations and automatic chaining of construct()
and destruct()
.
Define and override properties effortlessly.
Make instance properties non-writable, non-enumerable, or employ setters & getters with the properties
option, then inherit and override individually.
Dependencies
PseudoClass is completely standalone. All you need to stay classy is Class.js
.
Compatibility
As PseudoClass makes use of ECMAScript 5 features, it is only compatible with modern browsers.
- IE 9+
- Firefox 4+
- Chrome 6+
- Safari 5+
- Opera 12+
- Node 0.8+
PseudoClass can be used in a Node, AMD, or browser environment out of the box.
Usage
PseudoClass empowers you without getting in your way. See the examples below to see how PseudoClass makes prototypal inheritance painless.
Define a class
var Parent = ;
Define a mixin
A mixin is a set methods you can plug into any class. Mixins can use _super
, just like normal methods.
var stuffDoer = { this; console; };
Inherit from Parent and add a mixin to the class prototype
Mixins added at declaration time become part of the prototype.
var Child = Parent;
Create an instance
var child = new Child();
/* Output:
Parent: Constructing
Child: Constructing
*/
Call a method
child;/* Output: Parent: Doing stuff Child: Doing stuff Mixin: Doing stuff*/
Add a mixin to the instance
Mixins added after instantiation become part of the instance.
child; child;/* Output: Child: Doing more stuff*/
Check yo' self
console; // trueconsole; // trueconsole // trueconsole; // 'Child'
Wreck yo' self
child;/* Output: Child: Destructing Parent: Destructing*/
No-conflict by default
PseudoClass is always accessible as PseudoClass
. If you're using another library that defines Class
, you can still use PseudoClass by referencing PseudoClass
instead.
License
PseudoClass is licensed under the permissive BSD license.