Hi marioosh, TJ is right, when you call the doit function via fun, the 'this' value is equal to Object window. So you need a little more binding to resolve your problem:
replace the call to ""this.minimize(this.doit);"" by ""this.minimize (this.doit.bind(this));"" -- david On 17 fév, 15:33, "T.J. Crowder" <[email protected]> wrote: > Hi, > > I'll bet this is the problem line: > > > this.minimize(this.doit); > > You're assuming that 'this' is somehow bound to 'doit' when you pass > the reference. It isn't. When you later call fun(), 'this' is not > set to what you think it is within the call. JavaScript functions are > functions, not methods. More here: > > http://blog.niftysnippets.org/2008/03/mythical-methods.htmlhttp://blog.niftysnippets.org/2008/04/you-must-remember-this.htmlhttp://prototypejs.org/api/function/bindhttp://www.alistapart.com/articles/getoutbindingsituations > > HTH, > -- > T.J. Crowder > tj / crowder software / com > Independent Software Engineer, consulting services available > > On Feb 17, 1:16 pm, marioosh <[email protected]> wrote: > > > On 17 Lut, 13:30, david <[email protected]> wrote: > > > > Hi craig, > > > > I've tested the following code, and it works in FF3 !! > > > Test this (http://pastie.org/391632) - it does not work in FF: > > > <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" > > "http://www.w3.org/TR/xhtml1/DTD/..."> > > <html xmlns="http://www.w3.org/1999/xhtml"> > > <head> > > <script type="text/javascript" src="resources/scriptaculous- > > js-1.8.2/lib/prototype.js" ></script> > > <script type="text/javascript" src="resources/scriptaculous- > > js-1.8.2/src/scriptaculous.js" ></script> > > > </script> > > </head> > > <body> > > <div id="myId"> > > <input id="bt1" type="submit"></input> > > <input id="bt2" type="submit"></input> > > </div> > > > <script type="text/javascript"> > > > var Slider = Class.create({ > > initialize: function (elContainer) { > > this.elContainer = elContainer; > > this.minimize(this.doit); > > }, > > > minimize: function(fun) { > > new Effect.Morph(this.elContainer, { > > style: 'left: 940px;', > > duration: 0.3, > > afterFinish: function() { > > $(this.elContainer).setStyle({ > > left: '-940px' > > }); > > if(fun != null) { > > fun(); > > } > > }.bind(this) > > }); > > }, > > > doit: function () { > > } > > > }); > > > var SliderCategory = Class.create(Slider, { > > > initialize: function($super, elContainer) { > > $super(elContainer); > > }, > > > doit: function() { > > new Ajax.Updater(this.elContainer,'category_add.php',{ > > > onCreate: function () { > > }.bind(this), > > > onComplete: function(request,result) { > > }.bind(this) > > > }); > > } > > > }); > > > new SliderCategory('myId'); > > </script> > > </body> > > </html> --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
