console.log

Is it possible to bind a date/time to a console log?

对着背影说爱祢 提交于 2019-11-28 21:44:09
I have the following code: var myLog = console.log.bind(console, '[DEBUG]'); Which works find when I want to log things prepended with [DEBUG] to the console. Now I want to add a date/time to the log and I tried this: var myLog = console.log.bind(console, '[DEBUG ' + (new Date) + ']'); Which obviously does not work because it always logs the same time (the time that the .bind was called). Is there any way (using .bind ) to log the current time on each log without having to do this: var myLog = function(){ var args = ['[DEBUG ' + (new Date) + ']']; for(var i = 0; i < arguments.length; ++i) {

Difference between console.log() and console.debug()?

孤街醉人 提交于 2019-11-28 15:53:57
问题 Google has not been helpful for me, since searching for "console.debug" just brings up a bunch of pages that have the words "console" and "debug" on them. I'm wondering what the difference is between console.log() and console.debug() . Is there some way to use a bunch of console.debug() statements and then just flip a switch to easily shut off all debug statements from being sent to the console (like after launching a site)? 回答1: For at least IE, Firefox and Chrome consoles, .debug() is just

Why is same return type but result is difference [duplicate]

痴心易碎 提交于 2019-11-28 12:25:36
This question already has an answer here: What are the rules for JavaScript's automatic semicolon insertion (ASI)? 5 answers I have two function of same return type in java script but return type is difference. The using code of snipped id below function foo1() { return { bar: "hello" }; } function foo2() { return { bar: "hello" }; } calling the function.. console.log("foo1 returns:"); console.log(foo1()); console.log("foo2 returns:"); console.log(foo2()); Output the result .... foo1 returns: Object {bar: "hello"} foo2 returns: undefined That's because JavaScript interprets return { bar:

chrome devtools inconsistency array length

最后都变了- 提交于 2019-11-28 09:23:44
问题 I seem to have stumbled upon an inconsistency in Chrome DevTools. Above is a screenshot from the devtools. At first I am told that the printed object contains a Body and a Head . The head should be an array of length 1. When I expand, this array suddenly becomes length 2. When expanding the array in question I get the following; So there seems to be an empty string in the array as well. This empty string is what is causing some problems with my code which is what prompted me to investigate. I

Why I can't directly set console.log() as callback function

血红的双手。 提交于 2019-11-28 09:08:44
问题 Why this code doesn't work function callback(num, func) { for(var i = 0; i < num; i++) { func(); } } callback(4, console.log("Hello")); I know I have to do like this: callback(4, function() { console.log("hello"); }); But I still don't understand the reason why I have to do like that. 回答1: Lets step through it to help you visualise what is going on. When the interpreter reads your code, it evaluates function expressions inside-out. That is to say: callback(4, console.log("Hello")); // ^------

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

隐身守侯 提交于 2019-11-28 08:57:13
This question already has an answer here: Chrome/Firefox console.log always appends a line saying undefined 6 answers console.log("hi") gives undefined hi console.log(1+1) gives undefined 2 Whether it's a string or integer calculation, I get undefined then the correct answer. Why do I get the undefined message? Is there a good way to avoid it? 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

Firebug console: not showing console.log

五迷三道 提交于 2019-11-27 23:04:44
问题 I am trying to test something, and for one reason or another, while working in the Firebug console, I am unable to create an array of script tags on the HTML page using the getElementByTagName('script') method. I realize there is probably something stupid I am overlooking. This is the dummy HTML page: <html> <head> <title>Random Crapolla Page</title> <h1>Random Crapolla Page</h1> </head> <body> <div id="whyNot"> <p id="p1"> <a href="http://google.com">Here is link one</a><br /> <a href="http:

Console.log statements output nothing at all in Jest

三世轮回 提交于 2019-11-27 22:54:39
问题 console.log statements output nothing at all in Jest. This was working for me yesterday, and all of sudden, it's not working today. I have made zero changes to my config and haven't installed any updates. I'm not using the --forceExit option. Still seeing this issue. 回答1: As per comment on https://github.com/facebook/jest/issues/2441, Try setting verbose: false (or removing it) in the jest options in package.json. 回答2: You can run both options together like this --watch --verbose false if you

How to disable console.log messages based on criteria from specific javascript source (method, file) or message contents

半城伤御伤魂 提交于 2019-11-27 22:35:06
问题 I am working on project that uses quite a few js libraries and one of them is outputting awful lot into console, it is polluting the airwaves so bad that it makes it hard to debug.... I know how to disable logging completely by overriding console.log with this, (function (original) { console.enableLogging = function () { console.log = original; }; console.disableLogging = function () { console.log = function () {}; }; })(console.log); but how do it do that per source(file/url) of where

Difference between console.log and return in javascript? [closed]

♀尐吖头ヾ 提交于 2019-11-27 21:45:24
What are the instances when you would use console.log and return in javascript? I've just started learning javascript and I want to know what are some instances when I'd use them? From http://blogs.msdn.com/b/cdndevs/archive/2011/05/26/console-log-say-goodbye-to-javascript-alerts-for-debugging.aspx console.log will display the parameter passed to the log method in the console window. Use this method to display a string or variable in the console window. You can use the console class in your code as well, much like we can use JavaScript alerts. <script type = "text/javascript"> function