Hi,

in my application I need JS objects to represent some "business"
objects, which are represented on the page by an Element.
I would like to be able to tie the two together in such a way that I
can use them interchangeably.
This sounds like it should be a common pattern, so I was wondering
what the best practices are.

Example:

var Foo = Class.create({
  initialize: function(parent) {
    var element = Object.extend(new Element("div", { 'class': 'foo',
'id': 'myFoo' }), this);
    parent.insert(element);
  },

  bar: function() {
  }
  // more methods
};

Thanks to Object.extend I can easily call: $('myFoo').bar()
But I cannot do the opposite, for instance:

var foo = new Foo();
foo.childElements();

Note that it would just work if I could return 'element' (which now
behaves like Foo).
However, I've read http://dev.rubyonrails.org/ticket/11481 and it has
reasonable objections to letting the constructor return a value.

So, what gives? Any suggestion?

TIA,
  Andrea

--~--~---------~--~----~------------~-------~--~----~
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 [email protected]
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