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. Other Discussions
  3. The Weird and The Wonderful
  4. Making shortcuts even shorter

Making shortcuts even shorter

Scheduled Pinned Locked Moved The Weird and The Wonderful
javascriptannouncement
10 Posts 7 Posters 1 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.
  • G Offline
    G Offline
    gnjunge
    wrote on last edited by
    #1

    I found this in JS:

    function toggleDiv(divName)
    {
    $(divName).toggle();
    }

    So using the shortcut: toggleDiv('foo');, we would end up with 17 characters. Using the unusual long version: $('foo').toggle();, we would end up with 18 characters.

    L T M G C 6 Replies Last reply
    0
    • G gnjunge

      I found this in JS:

      function toggleDiv(divName)
      {
      $(divName).toggle();
      }

      So using the shortcut: toggleDiv('foo');, we would end up with 17 characters. Using the unusual long version: $('foo').toggle();, we would end up with 18 characters.

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

      perhaps the coder has a non-functioning $ key? :P

      G 1 Reply Last reply
      0
      • L Lost User

        perhaps the coder has a non-functioning $ key? :P

        G Offline
        G Offline
        gnjunge
        wrote on last edited by
        #3

        That's very considerate of you!

        1 Reply Last reply
        0
        • G gnjunge

          I found this in JS:

          function toggleDiv(divName)
          {
          $(divName).toggle();
          }

          So using the shortcut: toggleDiv('foo');, we would end up with 17 characters. Using the unusual long version: $('foo').toggle();, we would end up with 18 characters.

          T Offline
          T Offline
          Tony Pottier
          wrote on last edited by
          #4

          It's sad, but I've seen those kind of things so many times I hardly consider them horrible anymore.

          1 Reply Last reply
          0
          • G gnjunge

            I found this in JS:

            function toggleDiv(divName)
            {
            $(divName).toggle();
            }

            So using the shortcut: toggleDiv('foo');, we would end up with 17 characters. Using the unusual long version: $('foo').toggle();, we would end up with 18 characters.

            M Offline
            M Offline
            Malli_S
            wrote on last edited by
            #5

            Does user hate to see so many '$' on the screen ? :wtf:

            [Delegates]      [Virtual Desktop]      [Tray Me !]
            -Malli...! :rose:****

            1 Reply Last reply
            0
            • G gnjunge

              I found this in JS:

              function toggleDiv(divName)
              {
              $(divName).toggle();
              }

              So using the shortcut: toggleDiv('foo');, we would end up with 17 characters. Using the unusual long version: $('foo').toggle();, we would end up with 18 characters.

              G Offline
              G Offline
              GibbleCH
              wrote on last edited by
              #6

              Unfortunately you have to use the function nearly 50 times before it actually saves any keystrokes...

              1 Reply Last reply
              0
              • G gnjunge

                I found this in JS:

                function toggleDiv(divName)
                {
                $(divName).toggle();
                }

                So using the shortcut: toggleDiv('foo');, we would end up with 17 characters. Using the unusual long version: $('foo').toggle();, we would end up with 18 characters.

                C Offline
                C Offline
                Chris Maunder
                wrote on last edited by
                #7

                Was this a remnant of moving from the standard 'getElementById' to using a library such as jQuery that provides the '$' shortcut? Maybe it's not terrible after all. Maybe doing it this way a) saved many, many characters in the initial form b) allowed a very quick and safe way of transitioning to the new syntax

                cheers, Chris Maunder

                CodeProject.com : C++ MVP

                G 1 Reply Last reply
                0
                • C Chris Maunder

                  Was this a remnant of moving from the standard 'getElementById' to using a library such as jQuery that provides the '$' shortcut? Maybe it's not terrible after all. Maybe doing it this way a) saved many, many characters in the initial form b) allowed a very quick and safe way of transitioning to the new syntax

                  cheers, Chris Maunder

                  CodeProject.com : C++ MVP

                  G Offline
                  G Offline
                  gnjunge
                  wrote on last edited by
                  #8

                  Could be, only the project is very new (1 month old) and this function is used on 1 page only (so it was not much work to do a Search & Replace on 1 page).

                  L 1 Reply Last reply
                  0
                  • G gnjunge

                    I found this in JS:

                    function toggleDiv(divName)
                    {
                    $(divName).toggle();
                    }

                    So using the shortcut: toggleDiv('foo');, we would end up with 17 characters. Using the unusual long version: $('foo').toggle();, we would end up with 18 characters.

                    D Offline
                    D Offline
                    Douglas Dean
                    wrote on last edited by
                    #9

                    ...so he would have to use the function at least 60 times just to make up for the fixed cost of the function definition...

                    1 Reply Last reply
                    0
                    • G gnjunge

                      Could be, only the project is very new (1 month old) and this function is used on 1 page only (so it was not much work to do a Search & Replace on 1 page).

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

                      appreciate ur guts to write these lines of code

                      Ravie Busie Coding is my birth-right and bugs are part of feature my code has!

                      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