Thank you for your extremely informative response. This will sound dumb,
but I hadn't even realized that console.log and console.info were
JavaScript functions -- I thought they were something "special" to Firebug
only (whatever that means). Had I realized they were just functions, I
would never have attempted to use any kind of conditional statements within
the parentheses in the first place. All I've ever used as function
parameters were variables, primitive values, or other functions.
I've been reading about named function expressions since reading your post.
It seems they're useful for both recursion and debugging. I've gone back
and added names to all my methods, and the debugging is going much better
now.
I know I can use breakpoints with Firebug's stack trace panel, but that
slows me down a lot for my current task; I'm constantly reloading and
resizing the browser window, and I like seeing all the information flowing
down in one stream in the Console.
I found your statement that you can use the ternary operator as a function
parameter to be very interesting (and surprising). That turned out to be
true; however, the syntax you showed was slightly wrong -- at least it is
for the named versions I'm now using. Specifically... I'm testing my
"resize illustration" code, and the resizeIllus function can be triggered
either by various other code or by the user clicking directly on the
illustration. So if I begin the ternary operator this way, analogous (I
assume) to the code you suggested:
console.info( resizeIllus.caller.name ? ...etc.
...it throws a JS error if the user has clicked. Turns out I have to test
for the caller itself, not for caller.name, even though it's the name (of
the calling function) that I'm after. This works fine in Firebug:
console.info( resizeIllus.caller ?
"resizeIllus has been called by " +
resizeIllus.caller.name :
"resizeIllus was triggered with no caller,
so you probably clicked."
)
By the way, the click code itself was set up simply like this:
illustration.onclick = resizeIllus;
...and I don't know how to make Firebug identify an event like that as the
specific trigger (or caller) of a function, which would be an interesting
thing if it were possible. Actually, I guess I could wrap the whole thing
in another named function which would then be the caller... but in this
case it doesn't matter since if the resize wasn't triggered by a function
it must have been triggered by a click.
All very educational. Thanks again for your help!
P.S. I read this discussion group in my gmail account, and it displays
parts of the code I insert as underlined blue links, even though they're
not links at all. I have no idea why. It's a little annoying. Do other
people see parts of my code that way? Any idea how I can stop it from doing
that? Thanks.
Lawrence San
Business Writing: Santhology.com
Cartoon Stories for Thoughtful People: Sanstudio.com
On Mon, Jul 21, 2014 at 4:51 AM, Sebastian Zartner <
[email protected]> wrote:
> On Saturday, July 19, 2014 12:15:23 AM UTC+2, San wrote:
>>
>> I just learned something very basic about a limitation of Firebug -- so
>> basic that I suspect almost everyone here already knew this. I'm only
>> posting it here (at the risk of seeming rather ignorant) because I want to
>> make sure I don't misunderstand the situation.
>>
>> I have a method that, depending on where it's called from, sometimes
>> reports a meaningful caller and stack trace, and sometimes not. I
>> originally put this into my JavaScript file:
>>
>> console.info(
>> if( arguments.callee.caller.name ) {
>> " layout.adjust has been called by: " +
>> arguments.callee.caller.name
>> } else {
>> " layout.adjust caller is unclear, so here's a stack trace: "
>> console.trace() }
>> ) // end console.info
>>
>> The above didn't work; the console just reported a syntax error
>>
>
> As the error indicates you have a JavaScript syntax error in your script.
> The point here is that JavaScript doesn't allow to have if blocks or loops
> as function parameters. You need to use the ternery operator instead to
> achieve this:
>
> console.info(
> arguments.callee.caller.name ?
> " layout.adjust has been called by: " + arguments.callee.caller.name :
> " layout.adjust caller is unclear, so here's a stack trace: " +
> console.trace()
> )
>
> (with no further explanation)
>>
> The unclear syntax error message comes from Firefox. Firebug just displays
> it. I created bug 1041426
> <https://bugzilla.mozilla.org/show_bug.cgi?id=1041426> asking to improve
> it.
>
>
>> BTW, I also discovered while googling around that
>> 'arguments.callee.caller' is frowned upon (which I didn't know)
>>
> Right, you can read more about that at the Mozilla Developer Network
> <https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions_and_function_scope/arguments/callee>
> .
>
>
>> ; you're supposed to give a name to your anonymous function expression so
>> it ain't really anonymous and you can refer to it that way. But they seem
>> to be talking about function recursion, which I'm not doing, and also my
>> "functions" are really methods of my custom objects -- in this case
>> layout.adjust = function() { blah blah...
>>
> The function itself still doesn't have a name in this case. layout.adjust
> is just the variable that is holding the anonymous function. You may write
> this instead:
>
> layout.adjust = function layout_adjust() { ... }
>
> In the case of a function or method that can be called from various places
>> in various contexts, how do most Firebug users find out where it was called
>> from? I mean especially in cases where there's no reported caller or where
>> a stack trace is vague or uninformative.
>>
> The stack trace provides links at the right side pointing to were the
> functions were called. If you have a case where they are not shown or point
> to somewhere unexpected, please post a simple test case for this, so it can
> be investigated.
>
> Instead of logging the stack trace to the console, you can also set a
> breakpoint at the first line of the function. When the breakpoint gets hit,
> you'll see the stack trace within the *Stack* side panel
> <https://getfirebug.com/wiki/index.php?title=Stack_Side_Panel>.
>
> Sebastian
>
> --
> You received this message because you are subscribed to the Google Groups
> "Firebug" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at http://groups.google.com/group/firebug.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/firebug/7167e0aa-6b70-412d-96d1-949f0cd221bd%40googlegroups.com
> <https://groups.google.com/d/msgid/firebug/7167e0aa-6b70-412d-96d1-949f0cd221bd%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>
--
You received this message because you are subscribed to the Google Groups
"Firebug" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/firebug.
To view this discussion on the web visit
https://groups.google.com/d/msgid/firebug/CAMoMLKhejRQzvLm7uKEMmH%2BmgbkxsfN05WZ%2BSynhewtSgg%3DpHw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.