src/topiarist.js
function mixin(target, Mix) {
	assertArgumentOfType('function', target, ERROR_MESSAGES.NOT_CONSTRUCTOR, 'Target', 'mixin');

	Mix = toFunction(
		Mix,
		new TypeError(
			msg(
				ERROR_MESSAGES.WRONG_TYPE,
				'Mix',
				'mixin',
				'non-null object or function',
				Mix === null ? 'null' : typeof Mix
			)
		)
	);

	var targetPrototype = target.prototype, mixinProperties = Mix.prototype, resultingProperties = {};
	var mixins = nonenum(target, '__multiparents__', []);
	var myMixId = mixins.length;

	for (var property in mixinProperties) {
		// property might spuriously be 'constructor' if you are in ie8 and using a shim.
		if (typeof mixinProperties[property] === 'function' && property !== 'constructor') {
			if (property in targetPrototype === false) {
				resultingProperties[property] = getSandboxedFunction(myMixId, Mix, mixinProperties[property]);
			} else if (targetPrototype[property]['__original__'] !== mixinProperties[property]) {
				throw new Error(
					msg(
						ERROR_MESSAGES.PROPERTY_ALREADY_PRESENT,
						property,
						className(Mix, 'mixin'),
						className(target, 'target')
					)
				);
			}
		} // we only mixin functions
	}

	copy(resultingProperties, targetPrototype);
	mixins.push(Mix);

	clearAssignableCache(target, Mix);

	return target;
}
function mixin(target, Mix) {
	assertArgumentOfType('function', target, ERROR_MESSAGES.NOT_CONSTRUCTOR, 'Target', 'mixin');

	Mix = toFunction(
		Mix,
		new TypeError(
			msg(
				ERROR_MESSAGES.WRONG_TYPE,
				'Mix',
				'mixin',
				'non-null object or function',
				Mix === null ? 'null' : typeof Mix
			)
		)
	);

	var targetPrototype = target.prototype, mixinProperties = Mix.prototype, resultingProperties = {};
	var mixins = nonenum(target, '__multiparents__', []);
	var myMixId = mixins.length;

	for (var property in mixinProperties) {
		// property might spuriously be 'constructor' if you are in ie8 and using a shim.
		if (typeof mixinProperties[property] === 'function' && property !== 'constructor') {
			if (property in targetPrototype === false) {
				resultingProperties[property] = getSandboxedFunction(myMixId, Mix, mixinProperties[property]);
			} else if (targetPrototype[property]['__original__'] !== mixinProperties[property]) {
				throw new Error(
					msg(
						ERROR_MESSAGES.PROPERTY_ALREADY_PRESENT,
						property,
						className(Mix, 'mixin'),
						className(target, 'target')
					)
				);
			}
		} // we only mixin functions
	}

	copy(resultingProperties, targetPrototype);
	mixins.push(Mix);

	clearAssignableCache(target, Mix);

	return target;
}
function mixin ( target , Mix ) { assertArgumentOfType ( 'function' , target , ERROR_MESSAGES . NOT_CONSTRUCTOR , 'Target' , 'mixin' ) ; Mix = toFunction ( Mix , new TypeError ( msg ( ERROR_MESSAGES . WRONG_TYPE , 'Mix' , 'mixin' , 'non-null object or function' , Mix === null ? 'null' : typeof Mix ) ) ) ; var targetPrototype = target . prototype , mixinProperties = Mix . prototype , resultingProperties = { } ; var mixins = nonenum ( target , '__multiparents__' , [ ] ) ; var myMixId = mixins . length ; for ( var property in mixinProperties ) { // property might spuriously be 'constructor' if you are in ie8 and using a shim. if ( typeof mixinProperties [ property ] === 'function' && property !== 'constructor' ) { if ( property in targetPrototype === false ) { resultingProperties [ property ] = getSandboxedFunction ( myMixId , Mix , mixinProperties [ property ] ) ; } else if ( targetPrototype [ property ] [ '__original__' ] !== mixinProperties [ property ] ) { throw new Error ( msg ( ERROR_MESSAGES . PROPERTY_ALREADY_PRESENT , property , className ( Mix , 'mixin' ) , className ( target , 'target' ) ) ) ; } } // we only mixin functions } copy ( resultingProperties , targetPrototype ) ; mixins . push ( Mix ) ; clearAssignableCache ( target , Mix ) ; return target ; }
Mixes functionality in to a class.

<p>Only functions are mixed in.</p>

<p>Code in the mixin is sandboxed and only has access to a 'mixin instance' rather than the real instance.</p>

@memberOf topiarist
@param {function} target
@param {function|Object} Mix
Mixes functionality in to a class .