Last active
April 29, 2022 20:39
-
-
Save calvinmetcalf/6819318 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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