[Proto-Scripty] Re: Need clarification or guidance regarding arrays/hashes

2009-06-10 Thread david

Hi Luisgo,

I does the following test:

var test=$H({'1234':{},'12345':{}});
alert(test.inspect());
var myVar='123';
alert('string:'+Object.isString(myVar)+' / number:'+Object.isNumber
(myVar));
test.set(myVar,{});
alert(test.inspect());
myVar=1230;
alert('string:'+Object.isString(myVar)+' / number:'+Object.isNumber
(myVar));
test.set(myVar,{});
alert(test.inspect());
myVar=0456;
alert('string:'+Object.isString(myVar)+' / number:'+Object.isNumber
(myVar));
test.set(myVar,{});
alert(test.inspect());


And even if it's a number or a string, the input is well inserted in
the Hash.
I just have trouble in case the number the ID is a number beginning
with 0, it seems that it interpret strangly the value.

btw as you could see this code work (well !) in IE6 and FF3.0.
Your trouble is I think spmewhere else.

--
david

On 8 juin, 21:49, Luisgo lgo...@gmail.com wrote:
 I've been a long time user of prototype and feel very comfortable in
 most areas but this keeps coming up and I find it very annoying.

 I have a hash that, as the code executes is filled with numeric ID's
 as hash variable names. I basically need it to end up sort of like
 this:

     {
         '4567':{},
         '9546':{},
         '6497':{},
         ...
     }

 The problem is the IDs are passed as strings but casted as integers
 when I do:

     myHash.set( idPassedInVariable, {} );

 This causes the hash to be filled by undefined items where the
 missing numeric IDs would be. In the example above I would end up
 with 0 to 4566 being undefined and every space in between the rest of
 the keys.

 Am I doing something wrong? Isn't there a way to make set pass the
 string or is javascript simply going to force it to be a number?

 Thanks!
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Prototype  script.aculo.us group.
To post to this group, send email to prototype-scriptaculous@googlegroups.com
To unsubscribe from this group, send email to 
prototype-scriptaculous+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en
-~--~~~~--~~--~--~---



[Proto-Scripty] Re: Need clarification or guidance regarding arrays/hashes

2009-06-10 Thread Richard Quadling

2009/6/8 Luisgo lgo...@gmail.com:

 I've been a long time user of prototype and feel very comfortable in
 most areas but this keeps coming up and I find it very annoying.

 I have a hash that, as the code executes is filled with numeric ID's
 as hash variable names. I basically need it to end up sort of like
 this:

    {
        '4567':{},
        '9546':{},
        '6497':{},
        ...
    }

 The problem is the IDs are passed as strings but casted as integers
 when I do:

    myHash.set( idPassedInVariable, {} );

 This causes the hash to be filled by undefined items where the
 missing numeric IDs would be. In the example above I would end up
 with 0 to 4566 being undefined and every space in between the rest of
 the keys.

 Am I doing something wrong? Isn't there a way to make set pass the
 string or is javascript simply going to force it to be a number?

 Thanks!

 


Using FireBug, I entered ...

var a = {'4':{}, '8':{}, '12':{} }

and then ...

console.dir(a)

and got ...


 console.dir(a)

4
Object
8
Object
12
Object


Which is exactly what I would expect.

What if you cast the value as a string?

 myHash.set( String(idPassedInVariable), {} );


-- 
-
Richard Quadling
Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498r=213474731
Standing on the shoulders of some very clever giants!

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Prototype  script.aculo.us group.
To post to this group, send email to prototype-scriptaculous@googlegroups.com
To unsubscribe from this group, send email to 
prototype-scriptaculous+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en
-~--~~~~--~~--~--~---



[Proto-Scripty] Re: Need clarification or guidance regarding arrays/hashes

2009-06-10 Thread Richard Quadling

2009/6/10 david david.brill...@gmail.com:

 Hi Luisgo,

 I does the following test:

 var test=$H({'1234':{},'12345':{}});
 alert(test.inspect());
 var myVar='123';
 alert('string:'+Object.isString(myVar)+' / number:'+Object.isNumber
 (myVar));
 test.set(myVar,{});
 alert(test.inspect());
 myVar=1230;
 alert('string:'+Object.isString(myVar)+' / number:'+Object.isNumber
 (myVar));
 test.set(myVar,{});
 alert(test.inspect());
 myVar=0456;
 alert('string:'+Object.isString(myVar)+' / number:'+Object.isNumber
 (myVar));
 test.set(myVar,{});
 alert(test.inspect());


 And even if it's a number or a string, the input is well inserted in
 the Hash.
 I just have trouble in case the number the ID is a number beginning
 with 0, it seems that it interpret strangly the value.

 btw as you could see this code work (well !) in IE6 and FF3.0.
 Your trouble is I think spmewhere else.

 --
 david

 On 8 juin, 21:49, Luisgo lgo...@gmail.com wrote:
 I've been a long time user of prototype and feel very comfortable in
 most areas but this keeps coming up and I find it very annoying.

 I have a hash that, as the code executes is filled with numeric ID's
 as hash variable names. I basically need it to end up sort of like
 this:

     {
         '4567':{},
         '9546':{},
         '6497':{},
         ...
     }

 The problem is the IDs are passed as strings but casted as integers
 when I do:

     myHash.set( idPassedInVariable, {} );

 This causes the hash to be filled by undefined items where the
 missing numeric IDs would be. In the example above I would end up
 with 0 to 4566 being undefined and every space in between the rest of
 the keys.

 Am I doing something wrong? Isn't there a way to make set pass the
 string or is javascript simply going to force it to be a number?

 Thanks!
 


Numbers starting with a 0 are considered to be octal.

010 = 8
020 = 16
etc.

-- 
-
Richard Quadling
Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498r=213474731
Standing on the shoulders of some very clever giants!

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Prototype  script.aculo.us group.
To post to this group, send email to prototype-scriptaculous@googlegroups.com
To unsubscribe from this group, send email to 
prototype-scriptaculous+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en
-~--~~~~--~~--~--~---