Overload.js
function (def) {
	if (def) {
		var self = this,
			index,
			count,
			tmpDef,
			defNewKey,
			sigIndex,
			signatures;

		if (!(def instanceof Array)) {
			tmpDef = {};

			// Def is an object, make sure all prop names are devoid of spaces
			for (index in def) {
				if (def.hasOwnProperty(index)) {
					defNewKey = index.replace(/ /g, '');

					// Check if the definition array has a * string in it
					if (defNewKey.indexOf('*') === -1) {
						// No * found
						tmpDef[defNewKey] = def[index];
					} else {
						// A * was found, generate the different signatures that this
						// definition could represent
						signatures = this.generateSignaturePermutations(defNewKey);

						for (sigIndex = 0; sigIndex < signatures.length; sigIndex++) {
							if (!tmpDef[signatures[sigIndex]]) {
								tmpDef[signatures[sigIndex]] = def[index];
							}
						}
					}
				}
			}

			def = tmpDef;
		}

		return function () {
			var arr = [],
				lookup,
				type;

			// Check if we are being passed a key/function object or an array of functions
			if (def instanceof Array) {
				// We were passed an array of functions
				count = def.length;
				for (index = 0; index < count; index++) {
					if (def[index].length === arguments.length) {
						return self.callExtend(this, '$main', def, def[index], arguments);
					}
				}
			} else {
				// Generate lookup key from arguments
				// Copy arguments to an array
				for (index = 0; index < arguments.length; index++) {
					type = typeof arguments[index];

					// Handle detecting arrays
					if (type === 'object' && arguments[index] instanceof Array) {
						type = 'array';
					}

					// Handle been presented with a single undefined argument
					if (arguments.length === 1 && type === 'undefined') {
						break;
					}

					// Add the type to the argument types array
					arr.push(type);
				}

				lookup = arr.join(',');

				// Check for an exact lookup match
				if (def[lookup]) {
					return self.callExtend(this, '$main', def, def[lookup], arguments);
				} else {
					for (index = arr.length; index >= 0; index--) {
						// Get the closest match
						lookup = arr.slice(0, index).join(',');

						if (def[lookup + ',...']) {
							// Matched against arguments + "any other"
							return self.callExtend(this, '$main', def, def[lookup + ',...'], arguments);
						}
					}
				}
			}

			throw('Irrelon Overload: Overloaded method does not have a matching signature for the passed arguments: ' + JSON.stringify(arr));
		};
	}

	return function () {};
}
function (def) {
	if (def) {
		var self = this,
			index,
			count,
			tmpDef,
			defNewKey,
			sigIndex,
			signatures;

		if (!(def instanceof Array)) {
			tmpDef = {};

			// Def is an object, make sure all prop names are devoid of spaces
			for (index in def) {
				if (def.hasOwnProperty(index)) {
					defNewKey = index.replace(/ /g, '');

					// Check if the definition array has a * string in it
					if (defNewKey.indexOf('*') === -1) {
						// No * found
						tmpDef[defNewKey] = def[index];
					} else {
						// A * was found, generate the different signatures that this
						// definition could represent
						signatures = this.generateSignaturePermutations(defNewKey);

						for (sigIndex = 0; sigIndex < signatures.length; sigIndex++) {
							if (!tmpDef[signatures[sigIndex]]) {
								tmpDef[signatures[sigIndex]] = def[index];
							}
						}
					}
				}
			}

			def = tmpDef;
		}

		return function () {
			var arr = [],
				lookup,
				type;

			// Check if we are being passed a key/function object or an array of functions
			if (def instanceof Array) {
				// We were passed an array of functions
				count = def.length;
				for (index = 0; index < count; index++) {
					if (def[index].length === arguments.length) {
						return self.callExtend(this, '$main', def, def[index], arguments);
					}
				}
			} else {
				// Generate lookup key from arguments
				// Copy arguments to an array
				for (index = 0; index < arguments.length; index++) {
					type = typeof arguments[index];

					// Handle detecting arrays
					if (type === 'object' && arguments[index] instanceof Array) {
						type = 'array';
					}

					// Handle been presented with a single undefined argument
					if (arguments.length === 1 && type === 'undefined') {
						break;
					}

					// Add the type to the argument types array
					arr.push(type);
				}

				lookup = arr.join(',');

				// Check for an exact lookup match
				if (def[lookup]) {
					return self.callExtend(this, '$main', def, def[lookup], arguments);
				} else {
					for (index = arr.length; index >= 0; index--) {
						// Get the closest match
						lookup = arr.slice(0, index).join(',');

						if (def[lookup + ',...']) {
							// Matched against arguments + "any other"
							return self.callExtend(this, '$main', def, def[lookup + ',...'], arguments);
						}
					}
				}
			}

			throw('Irrelon Overload: Overloaded method does not have a matching signature for the passed arguments: ' + JSON.stringify(arr));
		};
	}

	return function () {};
}
function ( def ) { if ( def ) { var self = this , index , count , tmpDef , defNewKey , sigIndex , signatures ; if ( ! ( def instanceof Array ) ) { tmpDef = { } ; // Def is an object, make sure all prop names are devoid of spaces for ( index in def ) { if ( def . hasOwnProperty ( index ) ) { defNewKey = index . replace ( / / g , '' ) ; // Check if the definition array has a * string in it if ( defNewKey . indexOf ( '*' ) === - 1 ) { // No * found tmpDef [ defNewKey ] = def [ index ] ; } else { // A * was found, generate the different signatures that this // definition could represent signatures = this . generateSignaturePermutations ( defNewKey ) ; for ( sigIndex = 0 ; sigIndex < signatures . length ; sigIndex ++ ) { if ( ! tmpDef [ signatures [ sigIndex ] ] ) { tmpDef [ signatures [ sigIndex ] ] = def [ index ] ; } } } } } def = tmpDef ; } return function ( ) { var arr = [ ] , lookup , type ; // Check if we are being passed a key/function object or an array of functions if ( def instanceof Array ) { // We were passed an array of functions count = def . length ; for ( index = 0 ; index < count ; index ++ ) { if ( def [ index ] . length === arguments . length ) { return self . callExtend ( this , '$main' , def , def [ index ] , arguments ) ; } } } else { // Generate lookup key from arguments // Copy arguments to an array for ( index = 0 ; index < arguments . length ; index ++ ) { type = typeof arguments [ index ] ; // Handle detecting arrays if ( type === 'object' && arguments [ index ] instanceof Array ) { type = 'array' ; } // Handle been presented with a single undefined argument if ( arguments . length === 1 && type === 'undefined' ) { break ; } // Add the type to the argument types array arr . push ( type ) ; } lookup = arr . join ( ',' ) ; // Check for an exact lookup match if ( def [ lookup ] ) { return self . callExtend ( this , '$main' , def , def [ lookup ] , arguments ) ; } else { for ( index = arr . length ; index >= 0 ; index -- ) { // Get the closest match lookup = arr . slice ( 0 , index ) . join ( ',' ) ; if ( def [ lookup + ',...' ] ) { // Matched against arguments + "any other" return self . callExtend ( this , '$main' , def , def [ lookup + ',...' ] , arguments ) ; } } } } throw ( 'Irrelon Overload: Overloaded method does not have a matching signature for the passed arguments: ' + JSON . stringify ( arr ) ) ; } ; } return function ( ) { } ; }
Allows a method to accept overloaded calls with different parameters controlling
which passed overload function is called.
@param {Object} def
@returns {Function}
@constructor
Allows a method to accept overloaded calls with different parameters controlling which passed overload function is called .