|
Using the example below, is it possible to send the result of the callback function to the console, i.e. the value being returned?
rows.sort(function(a, b) { if(a.sortKey < b.sortKey) return -sortDirection; if(a.sortKey > b.sortKey) return sortDirection...
Started by chriswattsuk on
, 3 posts
by 3 people.
Answer Snippets (Read the full thread at stackoverflow):
Rows.sort(function(a, b) { var returnVal = 0 = sortDirection; console....
Fn){ return function() { var result = fn.apply(null, arguments); console.log(result); return result that, the return value is lost to the sort function.
|
|
Is there any way to turn off all console.log statements in my JavaScript code, for testing purposes?
Thanks!
Started by Zachary Burt on
, 5 posts
by 5 people.
Answer Snippets (Read the full thread at stackoverflow):
console.log = function() {}
That's it, no more() { oldConsoleLog = console.log; window['console']['log'] = function() {}; }; return pub; }(); $(document).ready....
Redefine the console.log function in your script.
|
|
I have a bunch of console.log calls in my JavaScript.
Should I comment them out before I deploy to production?
I'd like to just leave them there so I don't have to go to the trouble of removing the comments later on if I need to do any more debugging....
Started by Charlie Kotter on
, 9 posts
by 9 people.
Answer Snippets (Read the full thread at stackoverflow):
You should at least create a dummy console.log if the object doesn't exist so your code won't throw logging only in 'debug mode', ie if a certain flag is set:
if(_debug) console.log('foo'); _debug && console.log('foo');
It will cause....
|
Ask your Facebook Friends
|
I am debugging a Safari-specific javascript issue, and I can't get console.log to output to the error log. This is a documented feature of Safari (I'm using version 4.0.3). These statements in my code just seem to be ignored, however. Any ideas why? I...
Started by Eric Nguyen on
, 5 posts
by 5 people.
Answer Snippets (Read the full thread at stackoverflow):
This made me realize that it must[names[i]] = function() {} }
This was apparently written before Safari had implemented a console.
That console.log was, in fact, working in an isolated environment.
|
|
How to pass current scope variables and functions to the anonymous function in plain Javascript or in jQuery (if it's specific for frameworks).
For example:
jQuery.extend({ someFunction: function(onSomeEvent) { var variable = 'some text' onSomeEvent.apply...
Answer Snippets (Read the full thread at stackoverflow):
Not sure
So, this definitely will work:
function foo(){ console.log(this.a inside Functions....
So consider this example:
function bar(){ console.log(this.a); console.log(this.innerMethod(10 it's not needed.
Will be called.
|
|
Hi,
How is it possible to learn the name of function I am in?
The below code alerts 'Object'. But I need to know how to alert "Outer."
function Outer(){ alert(typeof this); }
Started by burak ozdogan on
, 3 posts
by 3 people.
Answer Snippets (Read the full thread at stackoverflow):
function callTaker(a,b,c,d,e){ // arguments properties console.log]); // Function properties console.log(callTaker.length); console.log(callTaker.caller); console.log); ....
On this, take a look at this article.
|
|
I am trying to dynamically call a function inside of an object. Found the apply function but not fully understanding it. Check out the code below, by triggering Test.checkQueue() it should in turn call showSomething "method". Thanks.
var Test = { , queue...
Started by Louis W on
, 3 posts
by 3 people.
Answer Snippets (Read the full thread at stackoverflow):
Instead of storing the name of the function in your queue, actually store the function:
queue(...)
There are (at least) two....
You could change your code in one of two ways .
The problem is that do.action is a string, not a function.
|
|
Can I call a function with multiple arguments in a convenient way in JavaScript?
example:
var fn = function() { console.log(arguments); } var args = [1,2,3]; fn(args);
I need arguments to be [1,2,3] just like my Array.
Started by David on
, 3 posts
by 3 people.
Answer Snippets (Read the full thread at stackoverflow):
function() { console.log(arguments); }; var args = [1,2,3]; fn.apply(null, args);
Apply will make = function() { var args = Array.prototype.slice.call(arguments), firstArg = args.shift(); console.log(args the equivalent ....
|
|
Var a = function(){ return 'test'; }(); console.log(a);
Answer in First Case : test
var a = (function(){ return 'test'; })(); console.log(a);
Answer in Second Case : test
I am using the the first approach to create self-executing functions. However, I...
Started by Rajat on
, 3 posts
by 3 people.
Answer Snippets (Read the full thread at stackoverflow):
The first syntax is only valid if you assign the result of the function execution to a variable, If you just want to execute the function....
The answer is no.
Edit: I read the first code wrong.
The variable a to the result of the function.
|
|
I'm trying to get the name of the currently running function. From what I've read, this should be possible using:
(arguments.callee.toString()).match(/function\s+(\[^\s\(]+)/)
However, when I run this in Firefox and Safari (latest versions on Mac) the...
Started by Geuis on
, 6 posts
by 6 people.
Answer Snippets (Read the full thread at stackoverflow):
/function\s+(\[^\s\(]+)/
What's with the backslash before [ ? I don't think recommend against anything....
You declared an anonymous function with
function(){
You should declare it as
function testfunc(){
to get the name printed.
|