oops!

I wanted to reference the values at fb.offSet.x so returning {x:w,y:h}
was perfect.

Obviously my understanding/comprehension of POJOs is a little lacking
as i thought i needed to return a some of hashed value to create the
reference.

Thanks for your help.
Techno~

On Dec 9, 11:40 am, "Techno~" <[EMAIL PROTECTED]> wrote:
> Hi,
>
> No you have understood me perfectly and provided the solution:
>
> I wanted t
>
> On Dec 9, 10:33 am, "T.J. Crowder" <[EMAIL PROTECTED]> wrote:
>
> > Hi,
>
> > Apologies in advance if I've misunderstood.
>
> > > How do I reference these returned hash values?
>
> > But it's no longer a Hash.  You've converted it to a string using
> > Hash#toJSON[1].  If you want it to be a Hash, don't convert it to a
> > string.  Change this:
>
> >     return $H({x: w, y: h}).toJSON();
>
> > to:
>
> >     return $H({x: w, y: h});
>
> > ...and then you can use the values via Hash#get[2], e.g., fb.offSet.get
> > ('x').
>
> > But taking things further:  Why make it a Hash?  Why not just use a
> > POJO?  (Plain Old JavaScript Object)  If you make that line:
>
> >     return {x: w, y: h};
>
> > ...then you can use the properties directly (fb.offSet.x) the way you
> > tried to initially.
>
> > [1]http://www.prototypejs.org/api/hash/tojson
> > [2]http://www.prototypejs.org/api/hash/get
>
> > HTH,
> > --
> > T.J. Crowder
> > tj / crowder software / com
>
> > On Dec 8, 4:10 pm, "Techno~" <[EMAIL PROTECTED]> wrote:
>
> > > I am trying to access a value that is returned via the $H.toJSON
> > > method.
>
> > > However, my alerts keeps saying that it is undefined.
>
> > > Any pointers gratefully received
>
> > > ==== code ====
> > > var Feedback = Class.create({
>
> > >         initialize: function() {
> > >                 this.offSet = this.getOffsets();
> > >         },
>
> > >         getOffsets: function() {
> > >                 if (window.innerHeight) {
> > >                         h = window.innerWidth;
> > >                         w = window.innerHeight;
> > >                 } else if (document.documentElement &&
> > > document.documentElement.clientHeight) {
> > >                         h = document.documentElement.clientWidth;
> > >                         w = document.documentElement.clientHeight;
> > >                 } else if (document.body) {
> > >                         h = document.body.clientWidth;
> > >                         w = document.body.clientHeight;
> > >                 }
>
> > >                 return $H({x: w, y: h}).toJSON();
> > >         }})
>
> > > ==== end code ====
>
> > > === mark-up snippet ===
> > >         <script type="text/javascript">
> > >                 var fb = new Feedback;
> > >         </script>
>
> > > <body onload="alert(fb.offSet.x)">
> > > === mark-up end ===
>
> > > if I alert(fb.offSet) I receive {"x":878,"y":1563}
>
> > > I have tried multiple variations:
>
> > > fb.offSet[0].x
> > > fb.offSet[x]
> > > fb.offSet[0]["x"]
> > > fb.offSet.x[0]
> > > fb.offSet[0].x[0]
>
> > > Some just error out some returned undefined.
>
> > > How do I reference these returned hash values?
>
> > > TIA
> > > Techno~
--~--~---------~--~----~------------~-------~--~----~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to