I'm usingconsole.log(value) however when I use console.log() If I wanted to play around with stuff and make it do other things is there a way I can create a function like...
var console.log = (function() { // something }
You could create a wrapper for the console.log function and then only use your wrapper to write to the console:
function myCustomConsoleLog() {
// do stuff with your arguments
console.log(arguments)
}
Now instead of calling console.log(vars) you would make a call to myCustomConsoleLog(vars).
console.log() here and pass through what I want into the console and it'll still act the same and I just add some other logic above that handles what I want?myCustomConsoleLog is doing in the end is calling the original console.log - but now you can do what ever you want before/after calling it.You don't need to declare console.log again because it's already declared.
In Javascript, console is a global variable. There is nothing preventing you from adding, editing or removing properties from it.
So yes, you can just assign a different function to console.log or whatever else you want:
console.log = function(foo, bar) { ... }
console.anotherProperty = { ... }
If however, you were trying to create a foo.bar variable that does not exist yet, you could do it in many different ways:
// first approach
var foo;
foo.bar = function() { ... };
// second approach
var foo = {
bar: function() { ... };
};
// third approach
var fnBar = function() { ... };
var foo = { bar: fnBar };
See more at Console API docs and Working with objects.
window.console = {};Or you could do this just to overwrite the function:console.log = function() { /* something */ }Which is equivalent to this:console["log"] = function() {}