Fiber.js: Lightweight, fast, JavaScript inheritance model
Why another JavaScript inheritance library?
Take a look at the performance tests to see how it compares against commonly used inheritance libraries.
Inheritance
Usage
[[constructor]].extend( function )
Example
// Animal base classvar Animal = Fiber;
The init
method acts as the constructor, which is invoked when an instance is created:
var animal = ; // Create a new Animal instance
init
is invoked automatically.
Inheritance
// Extend the Animal class.var Dog = Animal;
Create an instance of Dog
:
var husky = ;husky; // "Dog::I scare you'"
Accessing parent prototype
Every class definition has access to the parent's prototype via the first argument passed into the function:
// Extend the Animal class.var Dog = Animal;
Mixin
Mixins are a way to add functionality to a Fiber definition. Basically, they address the problem of "multiple inheritance". Read more.
Usage
Fiber.mixin( object, function1, function2, ... )
var Foo = Fiber; var f = ;f; var { return {} } Fiber; f;
Decorators
With decorators you can dynamically attach additional properties to an instance. Read more.
Usage
Fiber.decorate( instance, decorator_1, ... , decorator_n )
{ return {} } Fiber;
Proxy
Usage
Fiber.proxy( base, instance )
// Extend the Animal class;var Dog = Animal;
noConflict
Usage
Fiber.noConflict()
Returns a reference to the Fiber object, and sets the Fiber
variable to its previous owner.