Results 1 to 9 of 9

Thread: VS when "debugging" Javascript does not like this technique

  1. #1

    Thread Starter
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    VS when "debugging" Javascript does not like this technique

    I've been using tricks like this:

    Code:
    var strId = wesAWC.attr("id") || "";
    Basically OR'ing something that might come back as UNDEFINED with "" (in this example) - so that the strId variable gets "set" to blank instead.

    Like this also

    Code:
    var blnFullReMakeOnSave = (wesDDR.data("awcoptions") || {}).fullremakeonsave || false;
    I cannot guarantee that "awcoptions" will come back - so I "OR" it with an EMPTY OBJECT {} - and then OR .fullremakeonsave with FALSE in case it's not found in the OBJECT as well.

    At any rate - I bought a new PC and when I first hopped into VS it used IE as the default browser - and was debugging the code right in VS (I use FF with FireBug usually).

    The IE-debugger was breaking at all these spots telling me I that the "value" was undefined - which is the whole point of why I was OR'ing it with something EMPTY/BLANK.

    So - is this a bad technique I've picked up - or is the IE debugger stricter then it needs to be??

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  2. #2
    Frenzied Member tr333's Avatar
    Join Date
    Nov 2004
    Location
    /dev/st0
    Posts
    1,605

    Re: VS when "debugging" Javascript does not like this technique

    I see nothing wrong with that as long as wesDDR is defined and wesDDR.data exists as a function. Otherwise, you will get type errors if they don't exist.

    Just tried it in the Firefox and Chromium consoles, and no problems there getting "false".

    JavaScript Code:
    1. var wesDDR = {};
    2. wesDDR.data = function() {};
    3. var blnFullReMakeOnSave = (wesDDR.data("awcoptions") || {}).fullremakeonsave || false;
    4. // blnFullReMakeOnSave is now false
    CSS layout comes in to the 21st century with flexbox!
    Just another Perl hacker,

  3. #3
    Frenzied Member tr333's Avatar
    Join Date
    Nov 2004
    Location
    /dev/st0
    Posts
    1,605

    Re: VS when "debugging" Javascript does not like this technique

    I use that syntax all the time to create closures, and I've not seen any problems in IE8+.

    E.g.
    JavaScript Code:
    1. (function (wesDDR, $, undefined) {
    2.  
    3.     wesDDR.data = function () {
    4.  
    5.     };
    6.  
    7. })(window.wesDDR = window.wesDDR || {}, jQuery);
    CSS layout comes in to the 21st century with flexbox!
    Just another Perl hacker,

  4. #4
    Frenzied Member tr333's Avatar
    Join Date
    Nov 2004
    Location
    /dev/st0
    Posts
    1,605

    Re: VS when "debugging" Javascript does not like this technique

    Is "fullremakeonsave" supposed to be a property or a method? Did you see errors in the other browser consoles (Firefox web inspector, Chromium devtools, Opera dragonfly)?
    CSS layout comes in to the 21st century with flexbox!
    Just another Perl hacker,

  5. #5

    Thread Starter
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: VS when "debugging" Javascript does not like this technique

    I am trying to get the original error back again - but I've messed with so many settings related to IE debugging and IE script debugging and such.

    Argh!!

    At any rate - I'm not really having an issue here as much as I wanted to know that I not doing a bad thing with ||'ing like that.

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  6. #6
    Frenzied Member tr333's Avatar
    Join Date
    Nov 2004
    Location
    /dev/st0
    Posts
    1,605

    Re: VS when "debugging" Javascript does not like this technique

    Quote Originally Posted by szlamany View Post
    At any rate - I'm not really having an issue here as much as I wanted to know that I not doing a bad thing with ||'ing like that.
    You do have to be careful that the left operand of the || is not accidentally "truthy" when you really wanted it to be "falsey".

    http://james.padolsey.com/javascript/truthy-falsey/
    CSS layout comes in to the 21st century with flexbox!
    Just another Perl hacker,

  7. #7
    Frenzied Member tr333's Avatar
    Join Date
    Nov 2004
    Location
    /dev/st0
    Posts
    1,605

    Re: VS when "debugging" Javascript does not like this technique

    You could also golf it a bit by removing the second ||.

    JavaScript Code:
    1. var blnFullReMakeOnSave = !!(wesDDR.data("awcoptions") || {}).fullremakeonsave;

    http://www.bennadel.com/blog/1784-Us...pe-Casting.htm
    CSS layout comes in to the 21st century with flexbox!
    Just another Perl hacker,

  8. #8

    Thread Starter
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: VS when "debugging" Javascript does not like this technique

    Nice links - thanks!

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  9. #9
    Frenzied Member tr333's Avatar
    Join Date
    Nov 2004
    Location
    /dev/st0
    Posts
    1,605

    Re: VS when "debugging" Javascript does not like this technique

    Quote Originally Posted by szlamany View Post
    Nice links - thanks!
    And one more for good luck...

    http://net.tutsplus.com/tutorials/ja...in-javascript/
    CSS layout comes in to the 21st century with flexbox!
    Just another Perl hacker,

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width