Skip to content

Instantly share code, notes, and snippets.

@calvinmetcalf
Last active April 29, 2022 20:39
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save calvinmetcalf/6819318 to your computer and use it in GitHub Desktop.
Save calvinmetcalf/6819318 to your computer and use it in GitHub Desktop.
function makeFakeConsole(func){
return new Proxy({},{
get:function(target,name,receiver){
return function(){
//at some point if array.from gets implimented
//func(name,Array.from(arguments));
func(name,Array.prototype.slice.call(arguments));
}
}
});
}
makeFakeConsole(function(name, args){
if(typeof console[name] !== 'undefined'){
//in IE 9 console.foo isn't a real function
//and doesn't have an apply method
if(typeof console[name].apply === 'function'){
console[name].apply(console,args);
} else {
//this is why we can't have nice things
console[name](args.join(' '));
}
} else {
console.error('console.'+name +' is a lie');
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment