IgeClass

Method: implement

Copies all properties and methods from the classObj object to "this". If the overwrite flag is not set or set to false, only properties and methods that don't already exists in "this" will be copied. If overwrite is true, they will be copied regardless.
implement (Function classObj, Boolean overwrite)
  • FunctionclassObj
  • Booleanoverwrite

Implement all the methods of an object into another object

// Create a couple of test entities with ids
var entity1 = new IgeEntity().id('entity1'),
    entity2 = new IgeEntity().id('entity2');

// Let's define an object with a couple of methods
var obj = {
    newMethod1: function () {
        console.log('method1 called on object: ' + this.id());
    },

    newMethod2: function () {
        console.log('method2 called on object: ' + this.id());
    }
};

// Now let's implement the methods on our entities
entity1.implement(obj);
entity2.implement(obj);

// The entities now have the newMethod1 and newMethod2
// methods as part of their instance so we can call them:
entity1.newMethod1();

// The output to the console is:
//  method1 called on object: entity1

// Now let's call newMethod2 on entity2:
entity2.newMethod2();

// The output to the console is:
//  method2 called on object: entity2

// As you can see, this is a great way to add extra modular
// functionality to objects / entities at runtime.
© Copyright 2013 Irrelon Software Limited. All Rights Reserved. UK Registered Company Number: 07522767
Isogenic (ī´sōjen´ik): Adj originating from a common source; possessing the same genetic composition.
Strange Things Happen at the One Two Point