0.0.1 • Published 9 years ago

mix_factory v0.0.1

Weekly downloads
Last release
9 years ago

Mix Factory

Just two functions to make creating mixins more convenient.

mix(targetObject, method_name, method, enumerable, writable); Adds method, method_name to the target object's prototype. enumerable and writable and optional and default to false. returns the targetObject after alteration.

- example
function Hi(){};
function there(){return "there"};

// adds there to Hi.prototype
Hi = mix(Hi, "there", there);

// ....which is the same as ( both set enumerable and writable = false);
Hi = mix(Hi, "there", there, false, false);

// you could also: and set enumerable and writable to true;
Hi = mix(Hi, "there", there, true, true);

mixSet(targetObject, methodsInfo); Adds multiple methods to the target object. Simply calls mix multiple times on the same object.

  • methodsInfo argument is an array containing arrays of arguments to be passed to the mix function.
- example
function Hi(){};
function there(){return "there"};
function hi(){return "hi"};
function blam(){return "blam"}

// adds there to Hi.prototype
Hi = mixSet(Hi, [ 
		["there", there],
		["blam", blam, false, false],
		["hi", hi, true, false]

// which is the same as running these commands
Hi = mix(Hi, "there", there);
Hi = mix(Hi, "blam", blam, false, false);
Hi = mix(Hi, hi, true, false);