Hub
Namespace engine
by davidhong
JavaScript
if (!window.Hub) {
// move off global context for commonly used methods
var slice = Array.prototype.slice,
splice = Array.prototype.splice,
join = Array.prototype.join,
split = String.prototype.split;
///
/// var string = "Hello {0}!".format('David');
if (!String.prototype.format) {
String.prototype.format = function() {
var pattern = /\{\d+\}/g;
var args = arguments;
return this.replace(pattern, function(capture) {
return args[capture.match(/\d+/)];
});
};
}
/**
* Hub - core
*
* @required jQuery
* @class Hub
* @static
* @access private
*/
Hub = {
_logging: true,
_autostart: true,
_test: true,
/**
* Copy things from source to target
*
* @access private
* @param target {Object} where things will be copied into
* @param source {Object} where things will be copied from
* @param overwrite {Boolean} indicate if existing items should be overwritten
* @returns {Object} the target object
*/
copy: function(target, source, overwrite) {
var key;
for (key in source) {
if (overwrite || target[key] === undefined) {
target[key] = source[key];
}
}
return target;
},
/**
* Create a namespaced object under Hub
*
* @access private
* @param names {String} fully-qualified namespace (i.e,. 'UI.Views')
* @param value {Object} value to set. Default value is {}. [Optional]
*/
create: function(namespace, value) {
var node = window.Hub,
ns = namespace ? split.call(namespace, '.') : [],
depth = ns.length,
index = 0;
...