Hello,

I wanted to apply escape on every property of an object using the Hash.map method in prototype library. Check out this code:

<script type="text/javascript">

// Regular Array
var a = ["john doe", "[EMAIL PROTECTED]", "say hello to me"];
a.map(escape).each(function(x) {
  document.write(x + "<br />"); //nice and clean syntax
})

// Hash (not so elegant)
var h = $H({name: "john doe", email: "[EMAIL PROTECTED]", msg: "say hello to me"});
function escapeHash(x) {
  x[1] = escape(x[1]);
  return x;
}

h.map(escapeHash).each(function(x) {
  document.write(x[0] + " => " + x[1] + "<br />");
});

// This way would be nice
h.map(function(element, index) {
  return escape(element)
}).each(function(element, index)) {
  document.write(index + " => " + element + "<br />");
}

</script>

Is Prototype able to to this in a more elegant way?


TIA
Martin

 * * * * * * * * * * * * * * * * *
www.burnfield.com
www.pluxemburg.com
www.harald.net


_______________________________________________
Rails-spinoffs mailing list
Rails-spinoffs@lists.rubyonrails.org
http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs

Reply via email to