Though it's not like I wished to write it, but it's very interesting
to know for other cases.

For now I've done it how Mislav Marohnić described.

Thank you all

PS: sorry again for the wrong list

On May 7, 3:57 pm, "Ryan Gahl" <[EMAIL PROTECTED]> wrote:
> Couple things (issues explained 1 by 1)...
>
> First, in your code here you are accessing the add object as a static object
> on the class, when in fact it is a prototyped instance member. Meaning you
> first need to create an instance of your class to get at .add...
>
> var my_test_instance = new my_test();
> my_test_instance.add.txt();
>
> However... you are also missing an "initialize" function, which is necessary
> if you are using Class.create(). So you first have to rewrite your class
> like this:
>
> my_test.prototype = {
> textarea: 1,
> initialize: function() {},
> add: {
> txt: function() {
> console.log(this.textarea);
>
> }
> }
> }
>
> Then... like the others have been saying, even with a bind on that txt()
> function, the best you'd be doing is mapping "this" to the "add" object
> that's been tacked on to the prototype. If you are interested in writing
> this class in a manner similar to this, you must use a closure to wrap the
> object returned. To do this, turn "add" into a function that returns an
> object... (then .bind(this) on the methods of that object will work to map
> "this" to your my_test instance), however you must call add as a function.
> This pattern _can_ be helpful though under some more complicated scenarios.
> For now, it may be close to what you were looking for.
>
> my_test.prototype = {
> textarea: 1,
> initialize: function() {},
> add: function () {
> return {
> txt: function() {
> console.log(this.textarea);
>  }.bind(this)}
>
>  }
>  };
>
> var my_test_instance = new my_test();
> my_test_instance.add().txt();
>
> On 5/5/07, Christoph Roeder <[EMAIL PROTECTED]> wrote:
>
>
>
>
>
> > Hello,
>
> > I hope anybody can give me a hint why this dosn't work?
>
> > Thanks in advance
>
> > ~~~~~~~~~~~~~~~~
> > var my_test = Class.create();
> > my_test.prototype = {
> >     textarea: 1,
>
> >     add: {
> >         txt: function(){
> >             console.log(this.textarea);
> >         }
> >     }
> > }
>
> > my_test.add.txt();
>
> --
> Ryan Gahl
> Software Architect
> WebWidgetry.com / MashupStudio.com
> Future Home of the World's First Complete Web Platform
> Inquire: 1-262-951-6727
> Blog:http://www.someElement.com


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Prototype: Core" group.
To post to this group, send email to prototype-core@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-core?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to