Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    Regular Coder
    Join Date
    Oct 2002
    Posts
    299
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Global var optimalisation

    Hi,

    What is the better of these 2:

    1. Three global vars, like var1=Hello var2=Java_script var3=coders

    2. A string in one global var, like: var1=Hello#Java_script#coders

    Thanks for Your time,
    Jerome

  • #2
    New Coder
    Join Date
    Dec 2003
    Location
    Soraga, Trentino, Italy
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts
    it dipendes on what you will do with that values...

  • #3
    Regular Coder
    Join Date
    Jul 2002
    Posts
    698
    Thanks
    0
    Thanked 0 Times in 0 Posts
    if the value of the variables need to be accesed seperately I would go with 3 vars, since u then save from having to make string operations.

  • #4
    Master Coder
    Join Date
    Feb 2003
    Location
    UmeŚ, Sweden
    Posts
    5,575
    Thanks
    0
    Thanked 83 Times in 74 Posts
    How about:
    Code:
    var
        aVars = ['Hello','JavaScript','Coders'];
    or:
    Code:
    var
        oVars = {
            first: 'Hello',
            second: 'JavaScript',
            third: 'Coders'
        };
    liorean <[lio@wg]>
    Articles: RegEx evolt wsabstract , Named Arguments
    Useful Threads: JavaScript Docs & Refs, FAQ - HTML & CSS Docs, FAQ - XML Doc & Refs
    Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards

  • #5
    Regular Coder
    Join Date
    Oct 2002
    Posts
    299
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks for Your effort!

    I was also thinking about the global namespace necessary for each possibility, rather then the possible construction.

    Jerome

  • #6
    Master Coder
    Join Date
    Feb 2003
    Location
    UmeŚ, Sweden
    Posts
    5,575
    Thanks
    0
    Thanked 83 Times in 74 Posts
    The rule is simple: Only put things in the global namespace if you need them to be present from the time the page is parsed to the time the page is unloaded. That way you aren't polluting the global namespace. My way, you store each of them separate but still use only one global namespace slot, unlike the three separate vars. And, they are separate properties, instead of written as part of one string as in your example.
    Last edited by liorean; 01-10-2004 at 07:16 PM.
    liorean <[lio@wg]>
    Articles: RegEx evolt wsabstract , Named Arguments
    Useful Threads: JavaScript Docs & Refs, FAQ - HTML & CSS Docs, FAQ - XML Doc & Refs
    Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards

  • #7
    Regular Coder
    Join Date
    Oct 2002
    Posts
    299
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks Liorean!

    That's what I want to know

    Jerome


  •  

    Posting Permissions

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