Clean up some of the utility functions

This commit is contained in:
Andrew Stewart 2014-06-05 16:30:05 -07:00
parent f91dd7d5c3
commit 2b5e991ef3
1 changed files with 23 additions and 8 deletions

View File

@ -84,7 +84,9 @@ var Utils = module.exports = {
//
// Returns subclass
subclass: function subclass(child, parent) {
var ctor = function() { this.constructor = child; };
var ctor = function() {
this.constructor = child;
};
for (var key in parent) {
if (Object.hasOwnProperty.call(parent, key)) {
@ -109,8 +111,13 @@ var Utils = module.exports = {
//
// Returns base
proxyFunctionsToObject: function proxyFunctionsToObject(methods, target, base, force) {
if (base == null) { base = this; }
if (force == null) { force = false; }
if (base == null) {
base = this;
}
if (force == null) {
force = false;
}
var fn = function(method) {
return base[method] = function() {
@ -121,8 +128,9 @@ var Utils = module.exports = {
for (var i = 0; i < methods.length; i++) {
var method = methods[i];
if (!force) {
if (typeof base[method] === 'function') { continue; }
if (!force && typeof(base[method]) === 'function') {
continue;
}
fn(method);
@ -138,10 +146,15 @@ var Utils = module.exports = {
//
// Returns base
proxyTestStubs: function proxyTestStubs(methods, base) {
if (base == null) { base = this; }
if (base == null) {
base = this;
}
methods.forEach(function(method) {
base[method] = function() { return true; };
base[method] = function() {
return true;
};
base.commandList.push(method);
});
@ -165,7 +178,9 @@ var Utils = module.exports = {
//
// Returns a function wrapper
bind: function bind(fn, me) {
return function() { return fn.apply(me, arguments); };
return function() {
return fn.apply(me, arguments);
};
},
// Public: Adds necessary utils to global namespace, along with base class