[Proto-Scripty] Re: differences between mootools 'each' and Prototype 'Enumerable.each'

2009-07-11 Thread ronman

It works!  Thank you muchly.  Valuable for learning, too.

Now the code executes far enough to uncover another similar problem
which I think will go to my basic understanding of Javascript.  I'm
expecting it to act like PHP but I keep getting functions where I
expect values:

given:

attr: {
   edges: []
}


initialize: function($super,cv, id, attr) {

   // attr at this point is an object.  nice.

var myedges=$H(attr.edges);
myedges.each(function(edge, id) {

   // in the first place, I didn't expect to even get here because
myedges is an empty Hash, has no members.

  // but this shows the source code of a function!  I wanted the
value of a member of attr.edges (if it existed).
   alert(edge);

}, this);





On Jul 10, 4:15 pm, Rick Waldron waldron.r...@gmail.com wrote:
 The result your getting is completely correct, you're just missing one
 aspect...
 Take a look:

 http://jsbin.com/anefa

 (view source... )

 On Fri, Jul 10, 2009 at 4:57 PM, ronman ron.new...@gmail.com wrote:

  Hi,
  I've been puzzling over this for a couple of days and finally admit I
  need help.  I have a Hash of objects which I iterate over using each:

   $H(data.nodes).each(function(mynode,id) {
       alert(mynode);
       // do something with mynode
     },this);

  What I get back for 'mynode' is
  'nodename', [object Object]

  instead of what I need:
  [object Object]

  Here's the structure of the Hash, copied from Firebug.  If there's a
  better way to represent this, let me know:

  data:      Object nodes=Object size=[2]
   nodes:   Object node0=Object node1=Object
     node0:   Object label='node 0' height=0.44
     node1:   Object label='node 1' height=0.44
     node2:   Object label='node 2' height=0.44 width=1
     node3:   Object label='node 3' height=0.44 width=1
  .
  apparently the _each method of Hash in Prototype can't understand this
  structure, but I'm not seeing why it returns
  'nodename' and a comma before the object instead of just the object.

  Help!

  Ron
--~--~-~--~~~---~--~~
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: differences between mootools 'each' and Prototype 'Enumerable.each'

2009-07-11 Thread Rick Waldron
attr.edges is an array... keep it simple :)
http://jsbin.com/unohi


I just added to the last example, so view the source

Rick




On Sat, Jul 11, 2009 at 10:54 AM, ronman ron.new...@gmail.com wrote:


 It works!  Thank you muchly.  Valuable for learning, too.

 Now the code executes far enough to uncover another similar problem
 which I think will go to my basic understanding of Javascript.  I'm
 expecting it to act like PHP but I keep getting functions where I
 expect values:

 given:

 attr: {
   edges: []
 }


 initialize: function($super,cv, id, attr) {

   // attr at this point is an object.  nice.

var myedges=$H(attr.edges);
myedges.each(function(edge, id) {

   // in the first place, I didn't expect to even get here because
 myedges is an empty Hash, has no members.

  // but this shows the source code of a function!  I wanted the
 value of a member of attr.edges (if it existed).
   alert(edge);

}, this);





 On Jul 10, 4:15 pm, Rick Waldron waldron.r...@gmail.com wrote:
  The result your getting is completely correct, you're just missing one
  aspect...
  Take a look:
 
  http://jsbin.com/anefa
 
  (view source... )
 
  On Fri, Jul 10, 2009 at 4:57 PM, ronman ron.new...@gmail.com wrote:
 
   Hi,
   I've been puzzling over this for a couple of days and finally admit I
   need help.  I have a Hash of objects which I iterate over using each:
 
$H(data.nodes).each(function(mynode,id) {
alert(mynode);
// do something with mynode
  },this);
 
   What I get back for 'mynode' is
   'nodename', [object Object]
 
   instead of what I need:
   [object Object]
 
   Here's the structure of the Hash, copied from Firebug.  If there's a
   better way to represent this, let me know:
 
   data:  Object nodes=Object size=[2]
nodes:   Object node0=Object node1=Object
  node0:   Object label='node 0' height=0.44
  node1:   Object label='node 1' height=0.44
  node2:   Object label='node 2' height=0.44 width=1
  node3:   Object label='node 3' height=0.44 width=1
   .
   apparently the _each method of Hash in Prototype can't understand this
   structure, but I'm not seeing why it returns
   'nodename' and a comma before the object instead of just the object.
 
   Help!
 
   Ron
 


--~--~-~--~~~---~--~~
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: differences between mootools 'each' and Prototype 'Enumerable.each'

2009-07-11 Thread ronman

Using an array works when it's empty, but unfortunately normally
attr.edges is filled with rather complex objects.

(I wanted to print one of the objects out for you but can't get
Object.inspect(attr.edges)  to show anything but [object Object] .
Seems like javascript never wants to do what I expect!! )

So I'm back to trying to get each() work with a hash of complex
objects but also with an empty hash.

I'm porting legacy code from Mootools to Prototype.  So I'm trying to
understand why this works in Mootools but not Prototype.  The Mootools
Hash.each method is just:

  forEach: function(fn, bind){
for (var key in this){
  if (this.hasOwnProperty(key)) fn.call(bind, this[key], key,
this);
}
  },
});

Hash.alias('forEach', 'each');


And the Prototype each() is:

_each: function(iterator) {
  for (var key in this._object) {
var value = this._object[key], pair = [key, value];
pair.key = key;
pair.value = value;
iterator(pair);
  }
},


Ron



On Jul 11, 10:18 am, Rick Waldron waldron.r...@gmail.com wrote:
 attr.edges is an array... keep it simple :)http://jsbin.com/unohi

 I just added to the last example, so view the source

 Rick

 On Sat, Jul 11, 2009 at 10:54 AM, ronman ron.new...@gmail.com wrote:

  It works!  Thank you muchly.  Valuable for learning, too.

  Now the code executes far enough to uncover another similar problem
  which I think will go to my basic understanding of Javascript.  I'm
  expecting it to act like PHP but I keep getting functions where I
  expect values:

  given:

  attr: {
    edges: []
  }

  initialize: function($super,cv, id, attr) {

    // attr at this point is an object.  nice.

     var myedges=$H(attr.edges);
     myedges.each(function(edge, id) {

        // in the first place, I didn't expect to even get here because
  myedges is an empty Hash, has no members.

       // but this shows the source code of a function!  I wanted the
  value of a member of attr.edges (if it existed).
        alert(edge);

     }, this);

  On Jul 10, 4:15 pm, Rick Waldron waldron.r...@gmail.com wrote:
   The result your getting is completely correct, you're just missing one
   aspect...
   Take a look:

  http://jsbin.com/anefa

   (view source... )

   On Fri, Jul 10, 2009 at 4:57 PM, ronman ron.new...@gmail.com wrote:

Hi,
I've been puzzling over this for a couple of days and finally admit I
need help.  I have a Hash of objects which I iterate over using each:

 $H(data.nodes).each(function(mynode,id) {
     alert(mynode);
     // do something with mynode
   },this);

What I get back for 'mynode' is
'nodename', [object Object]

instead of what I need:
[object Object]

Here's the structure of the Hash, copied from Firebug.  If there's a
better way to represent this, let me know:

data:      Object nodes=Object size=[2]
 nodes:   Object node0=Object node1=Object
   node0:   Object label='node 0' height=0.44
   node1:   Object label='node 1' height=0.44
   node2:   Object label='node 2' height=0.44 width=1
   node3:   Object label='node 3' height=0.44 width=1
.
apparently the _each method of Hash in Prototype can't understand this
structure, but I'm not seeing why it returns
'nodename' and a comma before the object instead of just the object.

Help!

Ron
--~--~-~--~~~---~--~~
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: differences between mootools 'each' and Prototype 'Enumerable.each'

2009-07-11 Thread ronman

Actually, more to the point, what I tried to do originally was detect
an empty Hash and not go through each() at all in that case.  But
attr.edges.size() comes back as 32, not zero.   alert(attr.edges.size)
shows the source for the iterating function, as I said before, so
apparently size() gives the number of characters in that function.

how to make each() fall out in the cash of a hash of zero length or
work with arbitrary objects otherwise?

Thanks.

Ron


On Jul 11, 10:18 am, Rick Waldron waldron.r...@gmail.com wrote:
 attr.edges is an array... keep it simple :)http://jsbin.com/unohi

 I just added to the last example, so view the source

 Rick

 On Sat, Jul 11, 2009 at 10:54 AM, ronman ron.new...@gmail.com wrote:

  It works!  Thank you muchly.  Valuable for learning, too.

  Now the code executes far enough to uncover another similar problem
  which I think will go to my basic understanding of Javascript.  I'm
  expecting it to act like PHP but I keep getting functions where I
  expect values:

  given:

  attr: {
    edges: []
  }

  initialize: function($super,cv, id, attr) {

    // attr at this point is an object.  nice.

     var myedges=$H(attr.edges);
     myedges.each(function(edge, id) {

        // in the first place, I didn't expect to even get here because
  myedges is an empty Hash, has no members.

       // but this shows the source code of a function!  I wanted the
  value of a member of attr.edges (if it existed).
        alert(edge);

     }, this);

  On Jul 10, 4:15 pm, Rick Waldron waldron.r...@gmail.com wrote:
   The result your getting is completely correct, you're just missing one
   aspect...
   Take a look:

  http://jsbin.com/anefa

   (view source... )

   On Fri, Jul 10, 2009 at 4:57 PM, ronman ron.new...@gmail.com wrote:

Hi,
I've been puzzling over this for a couple of days and finally admit I
need help.  I have a Hash of objects which I iterate over using each:

 $H(data.nodes).each(function(mynode,id) {
     alert(mynode);
     // do something with mynode
   },this);

What I get back for 'mynode' is
'nodename', [object Object]

instead of what I need:
[object Object]

Here's the structure of the Hash, copied from Firebug.  If there's a
better way to represent this, let me know:

data:      Object nodes=Object size=[2]
 nodes:   Object node0=Object node1=Object
   node0:   Object label='node 0' height=0.44
   node1:   Object label='node 1' height=0.44
   node2:   Object label='node 2' height=0.44 width=1
   node3:   Object label='node 3' height=0.44 width=1
.
apparently the _each method of Hash in Prototype can't understand this
structure, but I'm not seeing why it returns
'nodename' and a comma before the object instead of just the object.

Help!

Ron
--~--~-~--~~~---~--~~
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: differences between mootools 'each' and Prototype 'Enumerable.each'

2009-07-10 Thread Rick Waldron
The result your getting is completely correct, you're just missing one
aspect...
Take a look:

http://jsbin.com/anefa


(view source... )


On Fri, Jul 10, 2009 at 4:57 PM, ronman ron.new...@gmail.com wrote:


 Hi,
 I've been puzzling over this for a couple of days and finally admit I
 need help.  I have a Hash of objects which I iterate over using each:

  $H(data.nodes).each(function(mynode,id) {
  alert(mynode);
  // do something with mynode
},this);


 What I get back for 'mynode' is
 'nodename', [object Object]


 instead of what I need:
 [object Object]


 Here's the structure of the Hash, copied from Firebug.  If there's a
 better way to represent this, let me know:

 data:  Object nodes=Object size=[2]
  nodes:   Object node0=Object node1=Object
node0:   Object label='node 0' height=0.44
node1:   Object label='node 1' height=0.44
node2:   Object label='node 2' height=0.44 width=1
node3:   Object label='node 3' height=0.44 width=1
 .
 apparently the _each method of Hash in Prototype can't understand this
 structure, but I'm not seeing why it returns
 'nodename' and a comma before the object instead of just the object.

 Help!

 Ron

 


--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---