Skip to content

Instantly share code, notes, and snippets.

@bionicbrian
Last active December 31, 2015 06:29
Show Gist options
  • Save bionicbrian/7948021 to your computer and use it in GitHub Desktop.
Save bionicbrian/7948021 to your computer and use it in GitHub Desktop.
var target = {};
target.show = function () {
[].slice.call(arguments).forEach(function (arg) {
console.log(arg);
});
};
target.wrap = function(name, wrapper) {
var context = Object.create(target);
context[name] = target[name].bind(target);
target[name] = function () {
var args = [].slice.call(arguments);
wrapper.apply(context, args);
};
return target;
};
var component = Object.create(target);
component.wrap("show", function (something, somethingElse) {
console.log("pre show");
this.show(something, somethingElse);
console.log("post show");
});
component.show("Something", "Something else");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment