Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Adding a `this._super()` that passes arguments along to a function's scope
function addSuper (subFn, superFn) {
return function () {
var self = this,
args = arguments;
this._super = function () {
return superFn.apply(self, args);
};
return subFn.apply(self, args);
}
}
// Example usage:
function supr () {
console.log('supr was called with', arguments);
}
function inc (x) {
this._super();
return x + 1;
}
inc = addSuper(inc, supr);
inc(2);
// console: 'supr was called with [2]'
// → 3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment