node package manager



JavaScript's native OO utilties don't need much neatening up; but it has some rough edges. Luma smooths them off; by doing as little as possible.



The main rough point that luma cleans up is the making of constructor functions.

    // instead of this:
    var Person = function(name){ = name
    Person.prototype = {
        greet: function(){
            return 'hi, I\'m ' +
    var hugh = new Person('hugh')
    // we have:
    var person = luma.factory({
        init: function(name){
   = name
            return this
      , greet: function(){
            return 'hi, I\'m ' +
    var hugh = person('hugh')

As with constructor functions, person.prototype will be the [[Prototype]] property of objects created.

There are a number of reasons for this design:

  • With the init function, any applicable value can be returned; whereas, with the new operator, only an object can be (otherwise, the object new implicitly creates is returned);
  • Avoids clobbering the namespace through a forgotten new in non-strict mode code.
  • no two-stage initialisation required for basic constructor creation.

creating single objects

Another rough edge to JS' OO is Object.create. Luma neatens it up by replacing property descriptor with object(s) to be mixed in to the created object:

    // instead of: 
    var person = { 
            greet: function(){
                return 'hi, I\'' +
      , hugh = Object.create(person) = 'hugh'
    // we have: 
    var person = { 
            greet: function(){
                return 'hi, I\'' +
      , hugh = luma.create(person, { name: 'hugh' })

You can mixin any number of objects this way. Let's imagine you want to create a person who also has Backbone's Event mixin:

    var hugh = luma.create(person, Backbone.Events, { name: 'hugh' })



    factory :: (proto) -> function

Creates an informal constructor (one that doesn't require new) function from a object (which is used as a prototype). If the prototype has an init method available on it, it will be called with the arguments passed to the constructor function.


    create :: (proto, [source]) -> object

Creates an object, with proto as its [[Prototype]] object. Any source objects will be mixed in to the return object.


    extend :: (destination, source, [extra sources] ) -> object

Same as underscore's extend, it shallow copies all enumerable properties from the source objects to the destination object. When there's a conflict; the rightmost object's property is preferred.

Getting setup

Get via npm:

    npm install luma

Or include as a regular script in the browser:

    <!-- after copying luma.js to your server -->
    <script src="/luma.js"></script> 


Luma is under the MIT license.