Restoring console.log()

Since original console is in window.console object, try restoring window.console from iframe: var i = document.createElement(‘iframe’); i.style.display = ‘none’; document.body.appendChild(i); window.console = i.contentWindow.console; // with Chrome 60+ don’t remove the child node // i.parentNode.removeChild(i); Works for me on Chrome 14.

Access function location programmatically

The answer, for now, is no. The [[FunctionLocation]] property you see in Inspector is added in V8Debugger::internalProperties() in the debugger’s C++ code, which uses another C++ function V8Debugger::functionLocation() to gather information about the function. functionLocation() then uses a number of V8-specific C++ APIs such as v8::Function::GetScriptLineNumber() and GetScriptColumnNumber() to find out the exact information. All … Read more

Show original order of object properties in console.log

console.log does indeed sort the properties, in some cases you can use JSON.stringify which preserves the order, e.g. console.log(JSON.stringify(obj, null /*replacer function */, 4 /* space */)) NB: contrary to the popular belief, js objects maintain the enumeration order, as per the OwnPropertyKeys specification (integers first, then other properties in insertion order)

console.log(myFunction()) returns undefined

In JavaScript, if nothing is returned from the function with the keyword return then undefined is returned by default. var data = greet(); console.log(data);// undefined, since your function does not return. Is equivalent to: console.log(greet()); The second output is the returned result from the function. Since you are not returning anything from the function hence … Read more

Configure Node.js to log to a file instead of the console

You could also just overload the default console.log function: var fs = require(‘fs’); var util = require(‘util’); var log_file = fs.createWriteStream(__dirname + ‘/debug.log’, {flags : ‘w’}); var log_stdout = process.stdout; console.log = function(d) { // log_file.write(util.format(d) + ‘\n’); log_stdout.write(util.format(d) + ‘\n’); }; Above example will log to debug.log and stdout. Edit: See multiparameter version by … Read more

Why does console.log say undefined, and then the correct value? [duplicate]

The console will print the result of evaluating an expression. The result of evaluating console.log() is undefined since console.log does not explicitly return something. It has the side effect of printing to the console. You can observe the same behaviour with many expressions: > var x = 1; undefined; A variable declaration does not produce … Read more

tech