src/topiarist.js
function toFunction(obj, couldNotCastError) {
	if (obj == null) {
		throw couldNotCastError;
	}

	var result;
	if (typeof obj === 'object') {
		if (obj.hasOwnProperty('constructor')) {
			if (obj.constructor.prototype !== obj) {
				throw couldNotCastError;
			}
			result = obj.constructor;
		} else {
			var EmptyInitialiser = function() {};
			EmptyInitialiser.prototype = obj;
			Object.defineProperty(obj, 'constructor', {
				enumerable: false, value: EmptyInitialiser
			});
			result = EmptyInitialiser;
		}
	} else if (typeof obj === 'function') {
		result = obj;
	} else {
		throw couldNotCastError;
	}
	return result;
}
function toFunction(obj, couldNotCastError) {
	if (obj == null) {
		throw couldNotCastError;
	}

	var result;
	if (typeof obj === 'object') {
		if (obj.hasOwnProperty('constructor')) {
			if (obj.constructor.prototype !== obj) {
				throw couldNotCastError;
			}
			result = obj.constructor;
		} else {
			var EmptyInitialiser = function() {};
			EmptyInitialiser.prototype = obj;
			Object.defineProperty(obj, 'constructor', {
				enumerable: false, value: EmptyInitialiser
			});
			result = EmptyInitialiser;
		}
	} else if (typeof obj === 'function') {
		result = obj;
	} else {
		throw couldNotCastError;
	}
	return result;
}
function toFunction ( obj , couldNotCastError ) { if ( obj == null ) { throw couldNotCastError ; } var result ; if ( typeof obj === 'object' ) { if ( obj . hasOwnProperty ( 'constructor' ) ) { if ( obj . constructor . prototype !== obj ) { throw couldNotCastError ; } result = obj . constructor ; } else { var EmptyInitialiser = function ( ) { } ; EmptyInitialiser . prototype = obj ; Object . defineProperty ( obj , 'constructor' , { enumerable : false , value : EmptyInitialiser } ) ; result = EmptyInitialiser ; } } else if ( typeof obj === 'function' ) { result = obj ; } else { throw couldNotCastError ; } return result ; }
Easier for us if we treat everything as functions with prototypes. This function makes plain objects behave that
way.
@private
Easier for us if we treat everything as functions with prototypes . This function makes plain objects behave that way .