Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. JavaScript
  4. var RVIPath = RVIPath || {};

var RVIPath = RVIPath || {};

Scheduled Pinned Locked Moved JavaScript
javascriptalgorithmsjson
14 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    fellathedog
    wrote on last edited by
    #1

    I am looking through JavaScript and searching the web to try to learn what it is doing. I see this as the first line of text. var RVIPath = RVIPath || {}; I know the || is a logical operator for OR. But the rest makes no sense to me.

    B J 2 Replies Last reply
    0
    • F fellathedog

      I am looking through JavaScript and searching the web to try to learn what it is doing. I see this as the first line of text. var RVIPath = RVIPath || {}; I know the || is a logical operator for OR. But the rest makes no sense to me.

      B Offline
      B Offline
      BobJanova
      wrote on last edited by
      #2

      I'm not sure what you're looking at. But what that does is assigns a new blank object ( {} ) to that variable if it didn't previously exist. (Actually, it also does it if that variable contains 0, false, an empty string, null or possibly an empty object or array, as well as undefined. But I'm sure its purpose is to ensure it is assigned to something before further processing.)

      F 1 Reply Last reply
      0
      • B BobJanova

        I'm not sure what you're looking at. But what that does is assigns a new blank object ( {} ) to that variable if it didn't previously exist. (Actually, it also does it if that variable contains 0, false, an empty string, null or possibly an empty object or array, as well as undefined. But I'm sure its purpose is to ensure it is assigned to something before further processing.)

        F Offline
        F Offline
        fellathedog
        wrote on last edited by
        #3

        Thanks Bob. But why the OR operand? Here is the rest of the code: // This function will open a new window with the URL of the Image requested. OpenImageWindow = function (ImageViewer, RVIPath) { if (RVIPath != "XX") { var hgt = screen.height - 20; var wdt = screen.width * .5; var lft = 1100; var window_chrome = "toolbar=no,resizable=yes,height=" + hgt + ",width=" + wdt; cas_window1 = window.open(RVIPath, "NewWindow", window_chrome); cas_ window1.focus(); } } // This function will read thru a subfile and determine if the the Image field has a "Y" in it. // If it does then it will set the field to " " and display the Scanner Images. // If it does not then it sets the field to " " and leaves the URL blank. DisplayScannerImage = function (elementsLength, imgCharField, imgImage, ScannerPath, startingID) { var startpoint = startingID; var next = startpoint; for (var i = 0; i < elementsLength; i++) { var imgtext = document.getElementById(imgCharField + next); var imgUrl = document.getElementById(imgImage + next); if ($(imgtext).text() != 'Y') { $(imgtext).text(' '); $(imgUrl).hide(); } if ($(imgtext).text() == 'Y') { $(imgtext).text(' '); $(imgUrl).attr('src', ScannerPath); } next = next + 1; } }

        L 1 Reply Last reply
        0
        • F fellathedog

          I am looking through JavaScript and searching the web to try to learn what it is doing. I see this as the first line of text. var RVIPath = RVIPath || {}; I know the || is a logical operator for OR. But the rest makes no sense to me.

          J Offline
          J Offline
          J4amieC
          wrote on last edited by
          #4

          This relies on the truthyness/falseyness concept in javascript, and the fact that as part of a boolean operation, javascript will coerce things to truthyness or falseyness. Falsey values in javascript are 0, null, undefined So what this code says is "If RVIPath is truthy, assign its value to RVIPath. Otherwise assign an empty object to RVIPath" It is a shorthand equivalent of

          var RVIPath = null;
          if(RVIPath)
          RVIPath = RVIPath;
          else
          RVIPath = {};

          1 Reply Last reply
          0
          • F fellathedog

            Thanks Bob. But why the OR operand? Here is the rest of the code: // This function will open a new window with the URL of the Image requested. OpenImageWindow = function (ImageViewer, RVIPath) { if (RVIPath != "XX") { var hgt = screen.height - 20; var wdt = screen.width * .5; var lft = 1100; var window_chrome = "toolbar=no,resizable=yes,height=" + hgt + ",width=" + wdt; cas_window1 = window.open(RVIPath, "NewWindow", window_chrome); cas_ window1.focus(); } } // This function will read thru a subfile and determine if the the Image field has a "Y" in it. // If it does then it will set the field to " " and display the Scanner Images. // If it does not then it sets the field to " " and leaves the URL blank. DisplayScannerImage = function (elementsLength, imgCharField, imgImage, ScannerPath, startingID) { var startpoint = startingID; var next = startpoint; for (var i = 0; i < elementsLength; i++) { var imgtext = document.getElementById(imgCharField + next); var imgUrl = document.getElementById(imgImage + next); if ($(imgtext).text() != 'Y') { $(imgtext).text(' '); $(imgUrl).hide(); } if ($(imgtext).text() == 'Y') { $(imgtext).text(' '); $(imgUrl).attr('src', ScannerPath); } next = next + 1; } }

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #5

            fellathedog wrote:

            But why the OR operand?

            It's a shorthand way of saying:

            if (RVIPath != NULL)
            RVIPath = RVIPath;
            else
            RVIPath = new object;
            // where else can be taken to mean or else

            // or in optimized form
            if (RVIPath == NULL)
            RVIPath = new object;

            One of these days I'm going to think of a really clever signature.

            F B 2 Replies Last reply
            0
            • L Lost User

              fellathedog wrote:

              But why the OR operand?

              It's a shorthand way of saying:

              if (RVIPath != NULL)
              RVIPath = RVIPath;
              else
              RVIPath = new object;
              // where else can be taken to mean or else

              // or in optimized form
              if (RVIPath == NULL)
              RVIPath = new object;

              One of these days I'm going to think of a really clever signature.

              F Offline
              F Offline
              fellathedog
              wrote on last edited by
              #6

              We had a missionary from Japan Sunday at church that said "the Japaneese language was created by the devil", in reference to it being hard to learn. Coming from a very safe comfortable environment to the web sometimes makes me think the same about JavaScript. I will learn this and be looking back and laughing at this comment. Thanks.

              L 1 Reply Last reply
              0
              • F fellathedog

                We had a missionary from Japan Sunday at church that said "the Japaneese language was created by the devil", in reference to it being hard to learn. Coming from a very safe comfortable environment to the web sometimes makes me think the same about JavaScript. I will learn this and be looking back and laughing at this comment. Thanks.

                L Offline
                L Offline
                Lost User
                wrote on last edited by
                #7

                fellathedog wrote:

                I will learn this and be looking back and laughing at this comment.

                As we all do from time to time ... :laugh:

                One of these days I'm going to think of a really clever signature.

                1 Reply Last reply
                0
                • L Lost User

                  fellathedog wrote:

                  But why the OR operand?

                  It's a shorthand way of saying:

                  if (RVIPath != NULL)
                  RVIPath = RVIPath;
                  else
                  RVIPath = new object;
                  // where else can be taken to mean or else

                  // or in optimized form
                  if (RVIPath == NULL)
                  RVIPath = new object;

                  One of these days I'm going to think of a really clever signature.

                  B Offline
                  B Offline
                  BobJanova
                  wrote on last edited by
                  #8

                  I don't know where the NULL comes from there. It is shorthand for

                  if(!RVIPath) RVIPath = {};

                  If RVIPath is assigned, but set to something which evaluates to false, it will be reassigned.

                  L 1 Reply Last reply
                  0
                  • B BobJanova

                    I don't know where the NULL comes from there. It is shorthand for

                    if(!RVIPath) RVIPath = {};

                    If RVIPath is assigned, but set to something which evaluates to false, it will be reassigned.

                    L Offline
                    L Offline
                    Lost User
                    wrote on last edited by
                    #9

                    Which is shorthand for

                    if(RVIPath == NULL) RVIPath = {};

                    The expression !object means object equals NULL.// the expression
                    if(!RVIPath)
                    // is shorthand for
                    if(!(RVIPath == NULL))
                    // or
                    if(RVIPath != NULL)

                    One of these days I'm going to think of a really clever signature.

                    B A 2 Replies Last reply
                    0
                    • L Lost User

                      Which is shorthand for

                      if(RVIPath == NULL) RVIPath = {};

                      The expression !object means object equals NULL.// the expression
                      if(!RVIPath)
                      // is shorthand for
                      if(!(RVIPath == NULL))
                      // or
                      if(RVIPath != NULL)

                      One of these days I'm going to think of a really clever signature.

                      B Offline
                      B Offline
                      BobJanova
                      wrote on last edited by
                      #10

                      Javascript is loosely typed. There's no guarantee that RVIPath was of type 'object' before arriving at this statement, and there are various other values it could have which would evaluate to 'false'.

                      L 1 Reply Last reply
                      0
                      • B BobJanova

                        Javascript is loosely typed. There's no guarantee that RVIPath was of type 'object' before arriving at this statement, and there are various other values it could have which would evaluate to 'false'.

                        L Offline
                        L Offline
                        Lost User
                        wrote on last edited by
                        #11

                        I was merely trying to explain syntax to OP, and I think my answer did that, and still holds true whether RVIPath is an object, a number or anything else.

                        One of these days I'm going to think of a really clever signature.

                        1 Reply Last reply
                        0
                        • L Lost User

                          Which is shorthand for

                          if(RVIPath == NULL) RVIPath = {};

                          The expression !object means object equals NULL.// the expression
                          if(!RVIPath)
                          // is shorthand for
                          if(!(RVIPath == NULL))
                          // or
                          if(RVIPath != NULL)

                          One of these days I'm going to think of a really clever signature.

                          A Offline
                          A Offline
                          Andy Brummer
                          wrote on last edited by
                          #12

                          I've gotten in the habit of doing !object with javascript because it is the least like any other programming language. Getting into the details of == and === in javascript is just too much of a PITA.

                          Curvature of the Mind now with 3D

                          L 1 Reply Last reply
                          0
                          • A Andy Brummer

                            I've gotten in the habit of doing !object with javascript because it is the least like any other programming language. Getting into the details of == and === in javascript is just too much of a PITA.

                            Curvature of the Mind now with 3D

                            L Offline
                            L Offline
                            Lost User
                            wrote on last edited by
                            #13

                            I have been doing that for nearly 30 years since I first read Kernighan & Ritchie[^]. I don't find Javascript that different, syntactically, from C or Java.

                            One of these days I'm going to think of a really clever signature.

                            A 1 Reply Last reply
                            0
                            • L Lost User

                              I have been doing that for nearly 30 years since I first read Kernighan & Ritchie[^]. I don't find Javascript that different, syntactically, from C or Java.

                              One of these days I'm going to think of a really clever signature.

                              A Offline
                              A Offline
                              Andy Brummer
                              wrote on last edited by
                              #14

                              Funny, it must be one of my handicaps from learning C++ before C. I think the vogue at the time was to avoid shortcuts like that and avoid shortcuts like if (!x) for pointers.

                              Richard MacCutchan wrote:

                              I don't find Javascript that different, syntactically, from C or Java.

                              Once I got into the details of it, the common syntax made things more complicated for me than if it was more foreign. When I read javascript now every time I see x != null instead of !x or x !== null, I immediately leap to the conclusion that the author is still thinking that everything works like C# and there are probably subtle bugs lurking in the code. Using the full on javascript style is a message to my future self that the code was written when I better understood the way javascript works.

                              Curvature of the Mind now with 3D

                              1 Reply Last reply
                              0
                              Reply
                              • Reply as topic
                              Log in to reply
                              • Oldest to Newest
                              • Newest to Oldest
                              • Most Votes


                              • Login

                              • Don't have an account? Register

                              • Login or register to search.
                              • First post
                                Last post
                              0
                              • Categories
                              • Recent
                              • Tags
                              • Popular
                              • World
                              • Users
                              • Groups