A very good idea, something I had pondered as well but never came up
with a solution I was satisfied with.
First problem with your scenario is you're sending in a string as the
superclass, this isn't going to work regardless. You could use new
Element('div') but this is going to create a static instance that all
instantiations of your Block class would use, not ideal.
As a quasi-solution you could use Element.addMethods to implement
extra functionality to a div object such that you could call your
highlight method.
Element.addMethods("div" { structOf : function });
http://prototypejs.org/api/element/addMethods
On Sep 26, 8:54 am, Rumith <[EMAIL PROTECTED]> wrote:
> Hi,
> I'm trying to implement a method that would allow to use
> Class.create() inheriting HTML elements like div instead of other
> classes. That is, the result would be something like this (the syntax
> is arbitrary and is for demo purposes only):
>
> var Block = Class.create("div", {
> initialize: function(bgColor) {
> this.style.backgroundColor = bgColor;
> },
>
> highlight: function() {
> ....
> },
>
> });
>
> var block = new Block("#aaaaff");
> document.getElementById("mountPoint").appendChild(block);
> block.highlight();
>
> The purpose is to defeat the necessity to maintain two JS objects (the
> actual DOM element and the object containing the special methods and
> the DOM element) per entity.
> Has anybody tried something like this? Can it be done without
> modifying Prototype itself? 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 [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
-~----------~----~----~----~------~----~------~--~---