Javascript Library.
Commands 0 |
---|
Change function context and add additional arguments.
_z.proxy(function, context);
Returns: function with new context Function
_z.proxy(context, function);
Returns: function with new context Function
_z.proxy(function, context, ...additionalArguments);
Returns: function with new context Function
<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>