Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
meta proxy as global __proto__
Window.prototype.__proto__ = forwarder(Window.prototype.__proto__);
function forwarder(target){
var traps = {
getOwnPropertyDescriptor: Object.getOwnPropertyDescriptor.bind(null, target),
getOwnPropertyNames: Object.getOwnPropertyNames.bind(null, target),
keys: Object.keys.bind(null, target),
defineProperty: Object.defineProperty.bind(null, target),
get: function(r,k){ return target[k] },
set: function(r,k,v){ target[k] = v; return true },
has: function(k){ return k in target },
hasOwn: function(k){ return {}, k) },
delete: function(k){ delete target[k]; return true },
enumerate: function(){ var i=0,k=[]; for (k[i++] in target); return k }
var names = {
get: 1,
set: 1,
has: 0,
hasOwn: 0,
delete: 0,
defineProperty: 0,
getOwnPropertyDescriptor: 0
return Proxy.create(Proxy.create({
get: function(r, trap){
return function(a, b, c, d){
if (trap in names)
console.log(trap, arguments[names[trap]])
if (trap in traps)
return traps[trap].apply(trap, arguments);
}), Object.getPrototypeOf(target));
Window.prototype.__proto__ = meta.proxy(Window.prototype.__proto__, meta.proxy({}, {
get: function(f, t, trap){
return function(fwd, target, key){
typeof key === 'string' ? console.log(trap, key) : console.log(trap);
return fwd();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment