Emery is a project mainly written in JavaScript, based on the MIT license.
Node.js extended
= Emery
NodeJS "à la" Ruby
== Install
== class and module
=== Create a class
var class = require('emery/class').class;
exports.MyClass = MaClass = class( ParentClass, { // Constructor initialize: function() { ... },
// Instance method
methodA: function() { ... },
// Class method
self$methodB: function() { ... },
...
} ); MaClass.include(MyModule);
MaClass.methodB();
var myInstance = new MaClass(); myInstance.methodA();
=== Create a module
var module = require('emery/module').module;
exports.MyModule = MyModule = module({ method1: function() { ... },
// ...
});
MyModule.method1();
== Enumerable
The Enumerable mixin provides collection classes with several traversal and searching methods, and with the ability to sort. The class must provide a method each, which yields successive members of the collection. If Enumerable#max, min, or sort is used, the objects in the collection must also implement a meaningful <=> operator, as these methods rely on an ordering between members of the collection.
=== Usage
var Enumerable = require('emery/enumerable').Enumerable
=== Methods
== EString
=== Usage
var EString = require('emery/string').EString;
=== Methods
== ENumber
=== Usage
var ENumber = require('emery/number').ENumber;
=== Methods
== EArray
EArrays are ordered, integer-indexed collections of any object. EArray indexing starts at 0, as in C or Java. A negative index is assumed to be relative to the end of the array—that is, an index of -1 indicates the last element of the array, -2 is the next to last element in the array, and so on.
=== Usage
var EArray = require('emery/array').EArray;
=== Included module
Enumerable
=== Methods
== EHash
=== Usage
var EHash = require('emery/hash').EHash;
=== Included module
Enumerable
=== Methods
== ERange
=== Usage
var ERange = require('emery/range').ERange;
=== Included module
Enumerable
=== Methods
== Exceptions
=== Error classes list
=== Raise an exception
throw( new Exception("message") )
Example :
var ZeroDivisionError = require('emery/exception').ZeroDivisionError;
function myFunction( value ) { var ret = 100/value;
if( ret == Infinity ) throw( new ZeroDivisionError("Zero division not allowed in myFunction!") );
return( 100/value );
}
try { v = myFunction( 0 ); } catch(e) { console.log(e); //=> #<ZeroDivisionError: Zero division not allowed in myFunction!> }
== Note on Patches/Pull Requests
== Inspiration
This lib was truly inspired by the awsome JS.Class (http://jsclass.jcoglan.com/) and php.js (http://phpjs.org)
== Copyright
Copyright (c) 2010 Gregoire Lejeune. See LICENSE for details.