UnderZ

Javascript Library.

Bind context and arguments to function.

Change function context and add additional arguments.


Bind function with context

_z.proxy(function, context);

Returns: function with new context Function


Bind context with function

_z.proxy(context, function);

Returns: function with new context Function


Bind function with context and additional arguments

_z.proxy(function, context, ...additionalArguments);

Returns: function with new context Function


Examples

<script>
// object
var obj = {
	name: "Object",
	func: function () {
			console.log([ this, arguments ]);
		},
	data: [ 1, 2, "a" ]
};

// function
function Myfn() {
	console.error([ this, arguments ]);
}

// Change context of function Myfn to document.body
_z.proxy(Myfn, document.body); // [body, []]

// Change context of function obj.func to obj
_z.proxy(obj, "func"); // [{ name: "Object", func: function () {}, data: [ 1, 2, "a" ] }, []]

// Change context of function obj.func to Myfn and attache additional arguments to it
_z.proxy(obj.func, Myfn, "a1", "a2", "b1"); // [function Myfn, ["a1", "a2", "b1"]]
</script>