Namespace comb
Defined in: index.js.
Constructor Attributes | Constructor Name and Description |
---|---|
Utilities for javascript, optimized for the server environment.
|
Method Attributes | Method Name and Description |
---|---|
<static> |
comb.broadcast(topic, params)
Broadcasts an event to all listeners
NOTE : the function takes a variable number of arguments
i.e.
|
<static> |
comb.connect(obj, method, cb, scope)
Function to listen when other functions are called
|
<static> |
comb.curry(depth, cb, scope)
Curries a function
|
<static> |
comb.define(super, proto)
Defines a new class to be used
Class methods
|
<static> |
comb.disconnect(A)
Disconnects a listener to a function
|
<static> |
comb.extend(parent, extend)
Extends the prototype of an object if it exists otherwise it extends the object.
|
<static> |
comb.hitch(scope, method, args)
Binds a method to a particular scope
|
<static> |
comb.isBoolean(obj)
Determines if obj is a boolean
|
<static> |
comb.isDate(obj)
Determines if obj is a Date
|
<static> |
comb.isEmpty(object)
Determines if an object is empty
|
<static> |
comb.isFunction(obj)
Determins if something is a function
|
<static> |
comb.isHash(obj)
Determins if an object is just a hash and not a qualified Object such as number
|
<static> |
comb.isInstanceOf(obj, Clazz)
Determines if obj is an instance of a particular class
|
<static> |
comb.isNull(obj)
Determines if obj is null
|
<static> |
comb.isNumber(obj)
Determines if obj is a number
|
<static> |
comb.isObject(obj)
Determines if obj is an object
|
<static> |
comb.isUndefined(obj)
Determines if obj is undefined
|
<static> |
comb.isUndefinedOrNull(obj)
Determines if obj is undefined or null
|
<static> |
comb.listen(topic, callback)
Listen for the broadcast of certain events
|
<inner> <static> |
comb.logging.Logger#-argsToArray(args)
Converts an arguments object to an array
|
<static> |
comb.merge(obj, props)
Merges objects together
NOTE: this function takes a variable number of objects to merge
|
<static> |
comb.partial(method, args)
Allows the passing of additional arguments to a function when it is called
especially useful for callbacks that you want to provide additional parameters to
|
<static> |
comb.singleton(super, proto)
Defines a singleton instance of a Class
|
<static> |
comb.unListen(handle)
Disconnects a listener
|
Method Detail
<static>
comb.broadcast(topic, params)
Broadcasts an event to all listeners
NOTE : the function takes a variable number of arguments
i.e. all arguments after the topic will be passed to the listeners
Defined in: broadcast.js.
Defined in: broadcast.js.
comb.broadcast("hello", "hello world"); //the args "hello" and "world" will be passed to any listener of the topic //"hello" comb.broadcast("hello", "hello", "world");
- Parameters:
- {String} topic
- the topic to brodcast
- params
- the information to bradcast
<static>
{Array}
comb.connect(obj, method, cb, scope)
Function to listen when other functions are called
Defined in: broadcast.js.
Defined in: broadcast.js.
comb.connect(obj, "event", myfunc); comb.connect(obj, "event", "log", console);
- Parameters:
- {Object} obj
- the object in which the method you are connection to resides
- {String} method
- the name of the method to connect to
- {Function} cb
- the function to callback
- {Object} scope Optional
- the scope to call the specified cb in
- Returns:
- {Array} handle to pass to comb.disconnect
<static>
{Function}
comb.curry(depth, cb, scope)
Curries a function
Defined in: functions.js.
Defined in: functions.js.
var curried = comb.curry(4, function(a,b,c,d){ return [a,b,c,d].join(","); } curried("a"); curried("b"); curried("c"); curried("d") => "a,b,c,d" //OR curried("a")("b")("c")("d") => "a,b,c,d"
- Parameters:
- {Number} depth
- the number of args you expect
- {Function} cb
- the function to call once all args are gathered
- {Object} scope Optional
- what scope to call the function in
- Returns:
- {Function} the curried version of the function
<static>
{Object}
comb.define(super, proto)
Defines a new class to be used
Defined in: define.js.
Class methods
- export(module | bject, name): exports the object to module or the object with the name
- mixin(mixin) : mixes in an object
- super(argumnents, [?newargs]): calls the super of the current method
- static: use to reference class properties and methods
Defined in: define.js.
//Class without a super class var Mammal = comb.define(null, { instance : { constructor: function(options) { options = options || {}; this.super(arguments); this._type = options.type || "mammal"; }, speak : function() { return "A mammal of type " + this._type + " sounds like"; }, //Define your getters getters : { type : function() { return this._type; } }, //Define your setters setters : { type : function(t) { this._type = t; } } }, //Define your static methods static : { soundOff : function() { return "Im a mammal!!"; } } }); //Show singular inheritance var Wolf = comb.define(Mammal, { instance: { constructor: function(options) { options = options || {}; //You can call your super constructor, or you may not //call it to prevent the super initializing parameters this.super(arguments); this._sound = "growl"; this._color = options.color || "grey"; }, speak : function() { //override my super classes speak //Should return "A mammal of type mammal sounds like a growl" return this.super(arguments) + " a " + this._sound; }, //add new getters for sound and color getters : { color : function() { return this._color; }, sound : function() { return this._sound; } }, setters : { //NOTE color is read only except on initialization sound : function(s) { this._sound = s; } } }, static : { //override my satic soundOff soundOff : function() { //You can even call super in your statics!!! //should return "I'm a mammal!! that growls" return this.super(arguments) + " that growls"; } } }); //Typical hierarchical inheritance // Mammal->Wolf->Dog var Dog = comb.define(Wolf, { instance: { constructor: function(options) { options = options || {}; this.super(arguments); //override Wolfs initialization of sound to woof. this._sound = "woof"; }, speak : function() { //Should return "A mammal of type mammal sounds like a growl thats domesticated" return this.super(arguments) + " thats domesticated"; } }, static : { soundOff : function() { //should return "I'm a mammal!! that growls but now barks" return this.super(arguments) + " but now barks"; } } }); dog instanceof Wolf => true dog instanceof Mammal => true dog.speak() => "A mammal of type mammal sounds like a woof thats domesticated" dog.type => "mammal" dog.color => "gold" dog.sound => "woof" Dog.soundOff() => "Im a mammal!! that growls but now barks" // Mammal->Wolf->Dog->Breed var Breed = comb.define(Dog, { instance: { //initialize outside of constructor _pitch : "high", constructor: function(options) { options = options || {}; this.super(arguments); this.breed = options.breed || "lab"; }, speak : function() { //Should return "A mammal of type mammal sounds like a //growl thats domesticated with a high pitch!" return this.super(arguments) + " with a " + this._pitch + " pitch!"; }, getters : { pitch : function() { return this._pitch; } } }, static : { soundOff : function() { //should return "I'M A MAMMAL!! THAT GROWLS BUT NOW BARKS!" return this.super(arguments).toUpperCase() + "!"; } } }); var breed = new Breed({color : "gold", type : "lab"}), breed instanceof Dog => true breed instanceof Wolf => true breed instanceof Mammal => true breed.speak() => "A mammal of type lab sounds like a woof " + "thats domesticated with a high pitch!" breed.type => "lab" breed.color => "gold" breed.sound => "woof" breed.soundOff() => "IM A MAMMAL!! THAT GROWLS BUT NOW BARKS!" //Example of multiple inheritance //NOTE proto is optional //Mammal is super class //Wolf Dog and Breed inject functionality into the prototype var Lab = comb.define([Mammal, Wolf, Dog, Breed]); var lab = new Lab(); lab instanceof Wolf => false lab instanceof Dog => false lab instanceof Breed => false lab instanceof Mammal => true lab.speak() => "A mammal of type mammal sounds like a" + " woof thats domesticated with a high pitch!" Lab.soundOff() => "IM A MAMMAL!! THAT GROWLS BUT NOW BARKS!"
- Parameters:
- {Array|Class} super
- the supers of this class
- {Object} proto Optional
- the object used to define this class
- {Object} proto.instance Optional
- the instance methods of the class
- {Object} proto.instance.getters Optional
- the getters for the class
- {Object} proto.instance.setters Optional
- the setters for the class
- {Object} proto.static Optional
- the Class level methods of this class
- {Object} proto.static.getters Optional
- static getters for the object
- {Object} proto.static.setters Optional
- static setters for the object
- Returns:
- {Object} the constructor of the class to be used with new keyword
<static>
comb.disconnect(A)
Disconnects a listener to a function
Defined in: broadcast.js.
Defined in: broadcast.js.
- Parameters:
- {handle} A
- handle returned from comb.connect
<static>
{Object}
comb.extend(parent, extend)
Extends the prototype of an object if it exists otherwise it extends the object.
Defined in: object.js.
Defined in: object.js.
var MyObj = function(){}; MyObj.prototype.test = true; comb.extend(MyObj, {test2 : false, test3 : "hello", test4 : "world"}); var myObj = new MyObj(); myObj.test => true myObj.test2 => false myObj.test3 => "hello" myObj.test4 => "world" var myObj2 = {}; myObj2.test = true; comb.extend(myObj2, {test2 : false, test3 : "hello", test4 : "world"}); myObj2.test => true myObj2.test2 => false myObj2.test3 => "hello" myObj2.test4 => "world"
- Parameters:
- {Object} parent
- the parent object to extend
- {Object} extend
- the extension object to mixin to the parent
- Returns:
- {Object} returns the extended object
<static>
{Function}
comb.hitch(scope, method, args)
Binds a method to a particular scope
Defined in: functions.js.
Defined in: functions.js.
- Parameters:
- {Object} scope
- the scope to bind the callback to
- {String|Function} method
- the method to callback
- {Anything} args Optional
- optional args to pass to the callback
- Returns:
- {Function} the hitched function
<static>
{Boolean}
comb.isBoolean(obj)
Determines if obj is a boolean
Defined in: misc.js.
Defined in: misc.js.
- Parameters:
- {Anything} obj
- the thing to test if it is a boolean
- Returns:
- {Boolean} true if it is a boolean false otherwise
<static>
{Boolean}
comb.isDate(obj)
Determines if obj is a Date
Defined in: date.js.
Defined in: date.js.
- Parameters:
- {Anything} obj
- the thing to test if it is a Date
- Returns:
- {Boolean} true if it is a Date false otherwise
<static>
comb.isEmpty(object)
Determines if an object is empty
Defined in: object.js.
Defined in: object.js.
comb.isEmpty({}) => true comg.isEmpty({a : 1}) => false
- Parameters:
- object
- the object to test
<static>
{Boolean}
comb.isFunction(obj)
Determins if something is a function
Defined in: functions.js.
Defined in: functions.js.
- Parameters:
- {Anything} obj
- the thing to test if it is a function
- Returns:
- {Boolean} true if the obj is a function false otherwise
<static>
{Boolean}
comb.isHash(obj)
Determins if an object is just a hash and not a qualified Object such as number
Defined in: object.js.
Defined in: object.js.
comb.isHash({}) => true comb.isHash({1 : 2, a : "b"}) => true comb.isHash(new Date()) => false comb.isHash(new String()) => false comb.isHash(new Number()) => false comb.isHash(new Boolean()) => false comb.isHash() => false comb.isHash("") => false comb.isHash(1) => false comb.isHash(false) => false comb.isHash(true) => false
- Parameters:
- {Anything} obj
- the thing to test if it is a hash
- Returns:
- {Boolean} true if it is a hash false otherwise
<static>
{Boolean}
comb.isInstanceOf(obj, Clazz)
Determines if obj is an instance of a particular class
Defined in: misc.js.
Defined in: misc.js.
- Parameters:
- {Anything} obj
- the thing to test if it and instnace of a class
- {Object} Clazz
- used to determine if the object is an instance of
- Returns:
- {Boolean} true if it is an instance of the clazz false otherwise
<static>
{Boolean}
comb.isNull(obj)
Determines if obj is null
Defined in: misc.js.
Defined in: misc.js.
- Parameters:
- {Anything} obj
- the thing to test if it is null
- Returns:
- {Boolean} true if it is null false otherwise
<static>
{Boolean}
comb.isNumber(obj)
Determines if obj is a number
Defined in: number.js.
Defined in: number.js.
- Parameters:
- {Anything} obj
- the thing to test if it is a Number
- Returns:
- {Boolean} true if it is a number false otherwise
<static>
{Boolean}
comb.isObject(obj)
Determines if obj is an object
Defined in: object.js.
Defined in: object.js.
- Parameters:
- {Anything} obj
- the thing to test if it is an object
- Returns:
- {Boolean} true if it is an object false otherwise
<static>
{Boolean}
comb.isUndefined(obj)
Determines if obj is undefined
Defined in: misc.js.
Defined in: misc.js.
- Parameters:
- {Anything} obj
- the thing to test if it is undefined
- Returns:
- {Boolean} true if it is undefined false otherwise
<static>
{Boolean}
comb.isUndefinedOrNull(obj)
Determines if obj is undefined or null
Defined in: misc.js.
Defined in: misc.js.
- Parameters:
- {Anything} obj
- the thing to test if it is undefined or null
- Returns:
- {Boolean} true if it is undefined or null false otherwise
<static>
comb.listen(topic, callback)
Listen for the broadcast of certain events
Defined in: broadcast.js.
Defined in: broadcast.js.
comb.listen("hello", function(arg1, arg2){ console.log(arg1); console.log(arg2); });
- Parameters:
- {String} topic
- the topic to listen for
- {Function} callback
- the funciton to call when the topic is published
- Returns:
- a handle to pass to comb.unListen
<inner> <static>
{Array}
comb.logging.Logger#-argsToArray(args)
Converts an arguments object to an array
Defined in: array.js.
Defined in: array.js.
- Parameters:
- {Arguments} args
- the arguments object to convert
- Returns:
- {Array} array version of the arguments object
<static>
{Object}
comb.merge(obj, props)
Merges objects together
NOTE: this function takes a variable number of objects to merge
Defined in: object.js.
Defined in: object.js.
var myObj = {}; comb.merge(myObj, {test : true}); myObj.test => true comb.merge(myObj, {test : false}, {test2 : false}, {test3 : "hello", test4 : "world"}); myObj.test => false myObj.test2 => false myObj.test3 => "hello" myObj.test4 => "world"
- Parameters:
- {Object} obj
- the object to merge into
- {Obejct} props
- variable number of objects to merge into the obj
- Returns:
- {Object} the merged object
<static>
{Function}
comb.partial(method, args)
Allows the passing of additional arguments to a function when it is called
especially useful for callbacks that you want to provide additional parameters to
Defined in: functions.js.
Defined in: functions.js.
- Parameters:
- {String|Function} method
- the method to callback
- {Anything} args Optional
- variable number of arguments to pass
- Returns:
- {Function} partially hitched function
<static>
comb.singleton(super, proto)
Defines a singleton instance of a Class
Defined in: define.js.
Defined in: define.js.
var MyLab = comb.singleton([Mammal, Wolf, Dog, Breed]); var myLab1 = new MyLab(); myLab1.type = "collie" var myLab2 = new MyLab(); myLab1 === myLab2 => true myLab1.type => "collie" myLab2.type => "collie" See {@link define}
- Parameters:
- super
- proto
<static>
comb.unListen(handle)
Disconnects a listener
Defined in: broadcast.js.
Defined in: broadcast.js.
- Parameters:
- handle
- a handle returned from comb.listen