console.log

Show original order of object properties in console.log

被刻印的时光 ゝ 提交于 2019-11-27 16:07:16
I need for some debugging to see the original order of one JavaScript object's properties but (at least in chrome devtools) console.log() shows me an alphabetically ordered object. Ex: var obj = { z: 1, t: 2, y: 3, a: 4, n: 5, k: 6 } console.log(obj) shows this: Object {z: 1, t: 2, y: 3, a: 4, n: 5…} a:4 k:6 n:5 t:2 y:3 z:1 //expected (needed ) original order z: 1 t: 2 y: 3 a: 4 n: 5 k: 6 georg 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:

Does console.log invokes toString method of an object?

只谈情不闲聊 提交于 2019-11-27 14:59:18
As per this documentation , The string representations of each of these objects are appended together in the order listed and output. Also as per answer The + x coerces the object x into a string, which is just [object Object]: So, my question is If I do str = new String("hello") console.log(str) //prints the string object but not 'hello' console.log(""+str) //prints "hello" So, in first case, it simply prints the object (doesn't invoke the toString() method). But in second case, it doesn't coerce but simply print the primitive value. Why is that so? Which method does console.log invokes to

Which browsers support console.log()?

∥☆過路亽.° 提交于 2019-11-27 14:35:20
Do all browsers support this? I would like to output an error using console.log() but was wondering if this supported by all browsers? console.log("Error etc"); No, not all browsers support console.log as it is not part of the standard and is an extension of the DOM and thus you should not count on its presence. To make your code resilient you should assume it does not exist and code accordingly. I've done something like this in the past: // Log to native console if possible, alert otherwise window.console = typeof window.console === 'undefined' ? {log:function(/* polymorphic */){alert

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

走远了吗. 提交于 2019-11-27 14:19:45
问题 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

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

允我心安 提交于 2019-11-27 07:00:21
问题 This question already has answers here : What are the rules for JavaScript's automatic semicolon insertion (ASI)? (5 answers) Closed 3 years ago . 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

Restoring console.log()

我是研究僧i 提交于 2019-11-27 06:44:00
For some reason, the prototype framework (or another JavaScript code) that is shipped with Magento is replacing standard console functions, so I can't debug anything. Writing down in JavaScript console console I get the following output: > console Object assert: function () {} count: function () {} debug: function () {} dir: function () {} dirxml: function () {} error: function () {} group: function () {} groupEnd: function () {} info: function () {} log: function () {} profile: function () {} profileEnd: function () {} time: function () {} timeEnd: function () {} trace: function () {} warn:

How do you send console messages and errors to alert?

廉价感情. 提交于 2019-11-27 02:43:48
问题 I would like to pass errors to an alert to warn the user they made mistake in their code even if they don't have console open. var doc=(frame.contentWindow.document || obj.contentDocument|| obj.contentWindow); var head = doc.getElementsByTagName('head')[0]; var scriptElement = doc.createElement('script'); scriptElement.setAttribute('type', 'text/javascript'); scriptElement.text = scripts; try{ head.appendChild(scriptElement); } catch(e){ alert("error:"+e.message +" linenumber:"+e.lineNumber);

Node.js: printing to console without a trailing newline?

主宰稳场 提交于 2019-11-26 21:13:37
Is there a method for printing to the console without a trailing newline? The console object documentation doesn't say anything regarding that: console.log() Prints to stdout with newline. This function can take multiple arguments in a printf() -like way. Example: console.log('count: %d', count); If formating elements are not found in the first string then util.inspect is used on each argument. onteria_ You can use process.stdout.write() : process.stdout.write("hello: "); See the docs for details . Also, if you want to overwrite messages in the same line, for instance in a countdown, you could

Which browsers support console.log()?

随声附和 提交于 2019-11-26 18:25:18
问题 Do all browsers support this? I would like to output an error using console.log() but was wondering if this supported by all browsers? console.log("Error etc"); 回答1: No, not all browsers support console.log as it is not part of the standard and is an extension of the DOM and thus you should not count on its presence. To make your code resilient you should assume it does not exist and code accordingly. 回答2: I've done something like this in the past: // Log to native console if possible, alert

Restoring console.log()

不想你离开。 提交于 2019-11-26 12:55:48
问题 For some reason, the prototype framework (or another JavaScript code) that is shipped with Magento is replacing standard console functions, so I can\'t debug anything. Writing down in JavaScript console console I get the following output: > console Object assert: function () {} count: function () {} debug: function () {} dir: function () {} dirxml: function () {} error: function () {} group: function () {} groupEnd: function () {} info: function () {} log: function () {} profile: function ()