Extends funcs w/ ES6 rest operator
by gavinfoley
HTML
<script src="https://getfirebug.com/firebug-lite-debug.js"></script>
TypeScript
// Some func that I want to be able to add some additional logic to,
// whenever it gets called (e.g. at some point in the future)
var myFunc = (foo, bar) => {
console.log(foo, bar);
};
///
// Add ref to original func before we replace it
var originalMyFunc = myFunc;
// New implmentation of myFunc
myFunc = (...args) => {
//console.debug(Array.isArray(...args), ...args); // false 1 2
//console.debug(Array.isArray(args), args); // true [1, 2]
// Call the original implementation of myFunc w/ args as individual params
originalMyFunc.call(this, ...args);
// or this would work
// originalMyFunc.apply(this, args);
// Now continue with our additional logic
console.log("3");
};
// Call func
myFunc(1, 2);