I've created the same classes in pure JS, and it's works... The problem come from (i suppose) Mootools, let's see what's wrong with the code using mootools.
The exemple in "pure" js : http://jsfiddle.net/neilime/R3nWq/3/ On 6 jan, 12:08, Neilime <[email protected]> wrote: > Here is the exemple :http://jsfiddle.net/neilime/8ebwd/ > > On 5 jan, 23:13, Oskar Krawczyk <[email protected]> wrote: > > > Please create an example on jsfiddle.net, and paste back a link. > > > On 2011-01-05, at 22:23, Neilime wrote: > > > > Hi, > > > > I've created a class who create an input element and assign options's > > > events to this element. > > > But when i bind this for the function's event the object isn't updated > > > if it has change. > > > > //Declare myClass > > > var myClass = new Class({ > > > Implements:[Options,Events], > > > options : { > > > 'name':'', > > > 'key':null > > > }, > > > > element : null, > > > firstParam : null, > > > > initialize : function(options){ > > > this.setOptions(options); > > > this.element = new Element('input',{ > > > 'type':'text' > > > }); > > > > if(Object.getLength(this.$events)){ > > > for(type in this.$events){ > > > var fFunc = this.$events[type][0].bind(this); > > > this.element.addEvent(type,fFunc); > > > } > > > }; > > > } > > > > }); > > > > //Declare mySecondClass > > > var mySecondClass = new Class({ > > > Implements: [Options, Events], > > > options: { > > > 'myClasses':[] > > > }, > > > > mainElement : null, > > > > initialize: function(options){ > > > this.setOptions(options); > > > this.mainElement = new > > > Element('div').inject(document.body); > > > this.myFunction(); > > > return this; > > > }, > > > > myFunction : function(){ > > > this.options.myClasses.each(function(tmpMyClass,key){ > > > console.log('update '+tmpMyClass.options.name+' => > > > '+key); > > > tmpMyClass.options.key = key; > > > tmpMyClass.options.firstParam = key; > > > tmpMyClass.element.inject(this.mainElement); > > > },this); > > > } > > > > }); > > > > //Launch myNewSecondClass > > > window.addEvent('domready',function(){ > > > myNewSecondClass = new mySecondClass({ > > > 'myClasses':[ > > > new myClass({ > > > 'name':'first class', > > > 'onBlur':function(that){ > > > console.log('first myClass options key : > > > ',this.options.key); > > > console.log('first myClass param : > > > ',this.firstParam); > > > } > > > }), > > > new myClass({ > > > 'name':'second class', > > > 'onBlur':function(that){ > > > console.log('second myClass options key : > > > ',this.options.key); > > > console.log('second myClass param : > > > ',this.firstParam); > > > } > > > }) > > > ] > > > }); > > > }); > > > > Console.log result : > > > > update first class => 0 > > > update second class => 1 > > > > //Blur first input : > > > first myClass options key : null > > > first myClass param : null > > > > //Blur second input : > > > second myClass options key : null > > > second myClass param : null > > > > It's very strange...
