Namespace comb
Defined in: index.js.
Method Detail
<inner> <static>
{Array}
comb.argsToArray(args)
Converts an arguments object to an array
Defined in: misc.js.
Defined in: misc.js.
- Parameters:
- {Arguments} args
- the arguments object to convert
- Returns:
- {Array} array version of the arguments object
<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.
Example 1 :
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
var args = Array.prototype.slice.call(arguments);
var topic = args.splice(0, 1)[0];
if (topic) {
var list = listeners[topic];
if (list) {
for (var i = list.length - 1; i >= 0; i--) {
var han = list[i], cb = han.cb;
if (cb) {
cb.apply(this, args);
}
}
}
}
<static>
{String}
comb.camelize(str)
Converts a string to camelcase
Defined in: inflections.js.
Defined in: inflections.js.
Example 1 :
comb.camelize('hello_world') => helloWorld
comb.camelize('column_name') => columnName
comb.camelize('columnName') => columnName
comb.camelize(null) => null
comb.camelize() => undefined
- Parameters:
- {String} str
- the string to camelize
- Returns:
- {String} the camelized version of the string
var ret = str;
if (!misc.isUndefinedOrNull(str)) {
ret = str.replace(CAMELIZE_CONVERT_REGEXP, function (a, b) {
return b.toUpperCase();
});
}
return ret;
<static>
{String}
comb.classify(str)
Singularizes and camelizes the string. Also strips out all characters preceding
and including a period (".").
Defined in: inflections.js.
Defined in: inflections.js.
Example 1 :
comb.classify('egg_and_hams') => "eggAndHam"
comb.classify('post') => "post"
comb.classify('schema.post') => "post"
- Parameters:
- {String} str
- the string to classify
- Returns:
- {String} the classified version of the string
var ret = str;
if (!misc.isUndefinedOrNull(str)) {
ret = comb.camelize(comb.singularize(str.replace(/.*\./g, '')));
}
return ret;
<static>
{Array}
comb.connect(obj, method, cb, scope)
Function to listen when other functions are called
Defined in: broadcast.js.
Defined in: broadcast.js.
Example 1 :
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
var index;
if (typeof method != "string") throw new Error("When calling connect the method must be string");
if (!func.isFunction(cb)) throw new Error("When calling connect callback must be a string");
var scope = obj || global, listeners, newMethod;
if (typeof scope[method] == "function") {
listeners = scope[method].__listeners;
if (!listeners) {
newMethod = wrapper();
newMethod.func = obj[method];
listeners = (newMethod.__listeners = []);
scope[method] = newMethod;
}
index = listeners.push(cb);
} else {
throw new Error("unknow method " + method + " in object " + obj);
}
return [obj, method, index];
<static>
comb.createFunctionWrapper(obj, handler, constructTrap, opts)
Creates a function proxy for an object.
Defined in: proxy.js.
Defined in: proxy.js.
Example 1 :
//create an object that can use properties or as a function through the new operator
var MyObject = comb.define(null, {
instance : {
hello : "hello",
constructor : function(){
this.args = comb.argsToArray(arguments);
}
}
});
//NOTE: this will not work properly for native objects like Date.
var createNewMyObject = function(){
try {
p = new MyObject();
} catch (ignore) {
//ignore the error because its probably from missing arguments
}
//Now lets take care of arguments supplied!!!
return MyObject.apply(p, comb.argsToArray(arguments));
};
//This example creates an object with a world property but its not a function!
var handle = comb.createFunctionWrapper({world : "world"}, createNewMyObject, createNewMyObject);
handle.world //=> "world"
var a = handle(1);
a.hello; //=>"hello"
a.args; //=> [1];
a = new handle(1,2);
a.hello; //=>"hello"
a.args; //=> [1,2];
- Parameters:
- obj
- the object to proxy
- {Function} handler
- the handler to call when the object is used as a function
- {Function} constructTrap
- the funciton to use when using new on the object
- {Object} opts
- the prototype of the object.
var args = misc.argsToArray(arguments), ret;
if (args.length != 4) {
opts = object.isHash(args[args.length - 1]) ? args.pop() : null;
constructTrap = functions.isFunction(args[args.length - 1]) ? args.pop() : null;
handler = functions.isFunction(args[args.length - 1]) ? args.pop() : null;
}
if (misc.isUndefined(obj)) throw new Error("obj required when using create function wrapper");
if (functions.isFunction(constructTrap) && !functions.isFunction(handler)) {
ret = Proxy.createFunction(handlerMaker(obj), constructTrap);
} else {
ret = Proxy.createFunction(handlerMaker(obj), handler, constructTrap);
}
if (opts) {
Proxy.setPrototype(ret, object.isHash(opts) ? opts : opts.prototype);
}
return ret;
<static>
{Function}
comb.curry(depth, cb, scope)
Curries a function
Defined in: functions.js.
Defined in: functions.js.
Example 1 :
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
var f;
if (scope) {
f = comb.hitch(scope, cb);
} else {
f = cb;
}
if (depth) {
var len = depth - 1;
for (var i = len; i >= 0; i--) {
f = curry(f, i == len);
}
}
return f;
<static>
{Object}
comb.define(super, proto)
Defines a new class to be used
Defined in: define.js.
Class methods
- as(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.
Example 1 :
//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
var child = function () {
var instance = this.__meta.proto.instance;
if (instance && instance.constructor && instance.constructor._unique) {
instance.constructor.apply(this, arguments);
} else {
var supers = this.__meta.supers, l = supers.length;
for (var i = 0; i < l; i++) {
var protoInstance = supers[i].__meta.proto.instance;
if (protoInstance && protoInstance.hasOwnProperty("constructor")) {
protoInstance.constructor.apply(this, arguments);
break;
}
}
}
};
var ret = __define(child, sup, proto);
if (typeof ret.init === "function") {
ret.init();
}
return ret;
<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
if (handle && handle.length == 3) {
var obj = handle[0], method = handle[1], cb = handle[2];
if (typeof method != "string") throw "comb.disconnect : When calling disconnect the method must be string";
var scope = obj || global, ls;
if (typeof scope[method] == "function") {
ls = scope[method].__listeners;
if (ls && cb-- > 0) {
ls[cb] = null;
}
} else {
throw new Error("unknown method " + method + " in object " + obj);
}
} else {
throw "comb.disconnect : invalid handle"
}
<static>
comb.executeInOrder(args, cb)
This method allows one to code asynchronous code in a synchronous manner.
Defined in: promise.js.
Using Object.define[rest of name] on objects passed will result in unexpected behavior. Enumerating passed in object keys is not currently supported. i.e for in loops on objects. using array enumeration methods will work though!!
Defined in: promise.js.
Example 1 :
var staticValueFunction = function (value) {
return comb.argsToArray(arguments).join(" ");
};
var promiseValueFunction = function (value) {
var ret = new comb.Promise();
setTimeout(comb.hitch(ret, "callback", comb.argsToArray(arguments).join(" ")), 100);
return ret;
};
var hash = {
staticValueFunction:staticValueFunction,
promiseValueFunction:promiseValueFunction
};
var p = comb.executeInOrder(hash, staticValueFunction, promiseValueFunction, function (hash, staticValueFunction, promiseValueFunction) {
var toBe = staticValueFunction(promiseValueFunction("to"), "be");
var notToBe = hash.promiseValueFunction("or", hash.staticValueFunction("not", toBe));
return hash.promiseValueFunction(toBe, notToBe);
});
p.addCallback(function(ret){
console.log(ret); //=>"to be or not to be"
});
- Parameters:
- {Object...} args
- variable number of objects.
- {Function} cb
- the function to callback to execute in order
- Returns:
- comb.Promise
args = base.argsToArray(arguments);
cb = base.isFunction(args[args.length - 1]) ? args.pop() : null;
var ret = new Promise();
if (cb) {
var stack = [];
var newArgs = args.map(function(a){
return [a, getHandler(a, stack)];
});
var cbRet = cb.apply(null, newArgs.map(function(h){
return h[1];
}));
executeStack(stack, newArgs).then(function(results, pMap){
if (base.isUndefined(cbRet)) {
ret.callback(results);
}
else {
var cbResults;
if (base.isArray(cbRet)) {
cbResults = cbRet.map(
function(arg){
return getValueFromArrayMap(arg, pMap, newArgs);
}).filter(function(r){
return !base.isUndefined(r)
});
} else if (base.isHash(cbRet)) {
cbResults = {};
for (var i in cbRet) {
cbResults[i] = getValueFromArrayMap(cbRet[i], pMap, newArgs);
}
} else if (base.isProxy(cbRet)) {
cbResults = getValueFromArrayMap(cbRet, pMap, newArgs);
} else {
cbResults = cbRet;
}
ret.callback(cbResults);
}
}, hitch(ret, "errback"));
} else {
ret.callback();
}
return ret;
<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.
Example 1 :
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
var proto = parent.prototype || parent; return exports.merge(proto, extend);
<static>
comb.handlerProxy(obj, opts)
Creates a proxy for an object.
Defined in: proxy.js.
Defined in: proxy.js.
- Parameters:
- obj
- object to proxy
- {Object} opts
- object with methods to define on the handler.
opts = opts || {};
return Proxy.create(merge(handlerMaker(obj), opts));
<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
- args Optional
- optional args to pass to the callback
- Returns:
- {Function} the hitched function
var args = Array.prototype.slice.call(arguments).slice(2);
if (typeof method == "string") {
method = scope[method];
}
if (method) {
return function() {
var scopeArgs = args.concat(Array.prototype.slice.call(arguments));
return method.apply(scope, scopeArgs);
};
} else {
throw new Error(method + "Method not defined");
}
<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
var undef, type = typeof obj; return obj != undef && type == "boolean" || type == "Boolean";
<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
var undef; return (obj !== undef && typeof obj === "object" && obj instanceof Date);
<static>
comb.isEmpty(object)
Determines if an object is empty
Defined in: object.js.
Defined in: object.js.
Example 1 :
comb.isEmpty({}) => true
comg.isEmpty({a : 1}) => false
- Parameters:
- object
- the object to test
if (object) {
for (var i in object) {
if (object.hasOwnProperty(i)) {
return false;
}
}
}
return true;
<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
return typeof obj == "function";
<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.
Example 1 :
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
var ret = comb.isObject(obj); return ret && obj.constructor === Object;
<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
return argsToArray(arguments).slice(1).some(function(c) {
return isInstance(obj, c);
});
<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
var undef; return obj !== undef && obj == null;
<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
var undef; return obj !== undef && obj != null && (typeof obj == "number" || obj instanceof Number);
<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
var undef; return obj != null && obj != undef && typeof obj == "object";
<static>
comb.isPromiseLike(obj)
Tests if an object is like a promise (i.e. it contains then, addCallback, addErrback)
Defined in: promise.js.
Defined in: promise.js.
- Parameters:
- obj
- object to test
return !base.isUndefinedOrNull(obj) && (base.isInstanceOf(obj, Promise) || (base.isFunction(obj.then) && base.isFunction(obj.addCallback) && base.isFunction(obj.addErrback)));
<static>
{Boolean}
comb.isProxy(obj)
Determines if the object is a proxy or not.
Defined in: proxy.js.
Defined in: proxy.js.
- Parameters:
- {Anything} obj
- object to test
- Returns:
- {Boolean} true if it is a proxy false otherwise
var undef; return obj !== undef && obj !== null && Proxy.isProxy(obj);
<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
var undef; return obj !== null && obj === undef;
<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
return comb.isUndefined(obj) || comb.isNull(obj);
<static>
comb.listen(topic, callback)
Listen for the broadcast of certain events
Defined in: broadcast.js.
Defined in: broadcast.js.
Example 1 :
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
if (!func.isFunction(callback)) throw new Error("callback must be a function");
var handle = {
topic : topic,
cb : callback,
pos : null
};
var list = listeners[topic];
if (!list) {
list = (listeners[topic] = []);
}
list.push(handle);
handle.pos = list.length - 1;
return handle;
<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.
Example 1 :
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
- {Object} props
- variable number of objects to merge into the obj
- Returns:
- {Object} the merged object
if (!obj) {
obj = {};
}
for (var i = 1, l = arguments.length; i < l; i++) {
merge(obj, arguments[i]);
}
return obj;
<static>
{Proxy}
comb.methodMissing(obj, handler, opts)
Creates a method missing proxy for an object.
NOTE: This method does not gurantee that the property will be used as a function call.
Defined in: proxy.js.
Defined in: proxy.js.
Example 1 :
var x = {hello:function () {return "hello"}, world:"world"};
var xHandler = comb.methodMissing(x, function (m) {
//you can do more interesting stuff in here!
return function () {
return [m].concat(comb.argsToArray(arguments));
}
});
xHandler.hello(); //=> "hello"
xHandler.world //=> "world"
xHandler.someMethod("hello", "world"); //=> [ 'someMethod', 'hello', 'world' ]
- Parameters:
- {Object} obj
- object to wrap with a method missing proxy
- {Function} handler
- handle to call when a property is missing
- {Object} opts
- prototype to assign to the proxy
- Returns:
- {Proxy} a proxy
proto = proto || {};
return Proxy.create(merge(handlerMaker(obj), noSuchMethodHandler(obj, handler)), object.isHash(proto) ? proto : proto.prototype);
<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
var args = Array.prototype.slice.call(arguments).slice(1);
if (typeof method == "function") {
return function() {
var scopeArgs = args.concat(Array.prototype.slice.call(arguments));
return method.apply(null, scopeArgs);
};
} else {
throw new Error(method + "Method not defined");
}
<static>
{String}
comb.pluralize(str)
Returns the plural form of the word in the string.
Defined in: inflections.js.
Defined in: inflections.js.
Example 1 :
comb.pluralize("post") => "posts"
comb.pluralize("octopus") => "octopi"
comb.pluralize("sheep") => "sheep"
comb.pluralize("words") => "words"
comb.pluralize("the blue mailman") => "the blue mailmen"
comb.pluralize("CamelOctopus") => "CamelOctopi"
- Parameters:
- {String} str
- the string to pluralize
- Returns:
- {String} the pluralized version of the string
var ret = str;
if (!misc.isUndefinedOrNull(str)) {
if (UNCOUNTABLES.indexOf(str) == -1) {
for (var i in PLURALS) {
var s = PLURALS[i], rule = s[0], replacement = s[1];
if ((ret = ret.replace(rule, replacement)) != str) {
break;
}
}
}
}
return ret;
<static>
comb.singleton(sup, proto)
Defines a singleton instance of a Class
Defined in: define.js.
Defined in: define.js.
Example 1 :
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:
- sup
- proto
var retInstance;
var child = function () {
if (!retInstance) {
var instance = this.__meta.proto.instance;
if (instance && instance.constructor._unique) {
instance.constructor.apply(this, arguments);
} else {
var supers = this.__meta.supers, l = supers.length;
for (var i = 0; i < l; i++) {
var protoInstance = supers[i].__meta.proto.instance;
if (protoInstance && protoInstance.hasOwnProperty("constructor")) {
protoInstance.constructor.apply(this, arguments);
break;
}
}
}
retInstance = this;
}
return retInstance;
};
var ret = __define(child, sup, proto);
if (typeof ret.init === "function") {
ret.init();
}
return ret;
<static>
{String}
comb.singularize(str)
The reverse of pluralize, returns the singular form of a word in a string.
Defined in: inflections.js.
Defined in: inflections.js.
Example 1 :
comb.singularize("posts") => "post"
comb.singularize("octopi")=> "octopus"
comb.singularize("sheep") => "sheep"
comb.singularize("word") => "word"
comb.singularize("the blue mailmen") => "the blue mailman"
comb.singularize("CamelOctopi") => "CamelOctopus"
- Parameters:
- {String} str
- the string to singularize
- Returns:
- {String} the singularized version of the string
var ret = str;
if (!misc.isUndefinedOrNull(str)) {
if (UNCOUNTABLES.indexOf(str) == -1) {
for (var i in SINGULARS) {
var s = SINGULARS[i], rule = s[0], replacement = s[1];
if ((ret = ret.replace(rule, replacement)) != str) {
break;
}
}
}
}
return ret;
<static>
{String}
comb.underscore(str)
The reverse of camelize. Makes an underscored form from the expression in the string.
Defined in: inflections.js.
Defined in: inflections.js.
Example 1 :
comb.underscore('helloWorld') => hello_world
comb.underscore('column_name') => column_name
comb.underscore('columnName') => column_name
comb.underscore(null) => null
comb.underscore() => undefined
- Parameters:
- {String} str
- The string to underscore
- Returns:
- {String} the underscored version of the string
var ret = str;
if (!misc.isUndefinedOrNull(str)) {
ret = str.replace(UNDERSCORE_CONVERT_REGEXP1, UNDERSCORE_CONVERT_REPLACE)
.replace(UNDERSCORE_CONVERT_REGEXP2, UNDERSCORE_CONVERT_REPLACE)
.replace(DASH, UNDERSCORE).toLowerCase();
}
return ret;
<static>
comb.unListen(handle)
Disconnects a listener
Defined in: broadcast.js.
Defined in: broadcast.js.
- Parameters:
- handle
- a handle returned from comb.listen
if (handle) {
var topic = handle.topic, list = listeners[topic];
if (list) {
for (var i = list.length - 1; i >= 0; i--) {
if (list[i] == handle) {
list.splice(i, 1);
}
}
if (!list.length) {
delete listeners[topic];
}
}
}
<static>
{comb.Promise}
comb.when(args, cb, eb)
Waits for promise and non promise values to resolve and fires callback or errback appropriately.
Defined in: promise.js.
Defined in: promise.js.
Example 1 :
var a = "hello"; var b = new comb.Promise().callback(world); comb.when(a, b) => called back with ["hello", "world"];
- Parameters:
- {Anything...} args
- variable number of arguments to wait for
- {Function} cb
- the callback function
- {Function} eb
- the errback function
- Returns:
- {comb.Promise} a promise that is fired when all values have resolved
var args = base.argsToArray(arguments), p;
eb = base.isFunction(args[args.length - 1]) ? args.pop() : null;
cb = base.isFunction(args[args.length - 1]) ? args.pop() : null;
if (eb && !cb) {
cb = eb;
eb = null;
}
if (!args.length) {
p = new Promise().callback(args);
} else if (args.length == 1) {
args = args.pop();
p = exports.isPromiseLike(args) ? args : new Promise().callback(args);
} else {
var p = new PromiseList(args.map(function(a){
return exports.isPromiseLike(a) ? a : new Promise().callback(a);
}), true);
}
if (cb) {
p.addCallback(cb);
}
if (eb) {
p.addErrback(eb);
}
return p;
Documentation generated by JsDoc Toolkit 2.4.0 on Tue Jan 31 2012 16:14:11 GMT-0600 (CST)