Skip to content

Instantly share code, notes, and snippets.

@kainino0x
Created November 23, 2015 03:00
Show Gist options
  • Save kainino0x/ef6a30671d62f724e99e to your computer and use it in GitHub Desktop.
Save kainino0x/ef6a30671d62f724e99e to your computer and use it in GitHub Desktop.
hijack.js
var hijack = function(that, name, wrap) {
var f0 = that[name];
that[name] = function() {
var f = function() {
f0.apply(that, arguments);
};
var args = Array.prototype.slice.call(arguments);
args.unshift(f);
return wrap.apply(null, args);
};
};
// Example:
//
// hijack(gl, 'drawArrays', function(f, mode, first, count) {
// console.log('gl.drawArrays(', mode, first, count, ')');
// return f(mode, first, count);
// });
//
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment