Steve Conover
2006-Jan-29 04:55 UTC
problem with xul/prototype experiment: "bind" method not found
Hi everyone, I was playing around with xul + prototype, and everything seemed to be going well until I ran into a wall - there seems to be some problem I can''t explain with Function.prototype.bind, for instance when I run this code: try { new Ajax.Request("http://localhost:3000/search/hello", { onComplete: this.onHelloComplete.bind(this) }); } catch (e) { alert(e); } I get an exception printed that says "TypeError: this.onHelloComplete.bind is not a function". I''ve done some more experimenting and confirmed that my functions just don''t have bind methods. I''m a little fuzzy on the more advanced aspects of javascript like this: can someone more knowledgable please give me a brief explanation about why "bind" works? In other words, how is it that Function.prototype.bind is available on every function object? I can''t get my head wrapped around the "bind" implementation... And if anyone has more direct ideas on what the problem could be (why it''s not working in the xul environment specifically), I''d love to hear them. Thanks, Steve
Steve Conover
2006-Jan-29 20:02 UTC
Re: problem with xul/prototype experiment: "bind" method not found
Just for the record, I figured out the problem. There is a bug in the XUL JS engine (going WAY back) that prevents methods from being added dynamically to Function or RegExp. Apparently other classes should be ok. References: http://groups.google.com/group/netscape.public.mozilla.jseng/browse_thread/thread/333a37784e94bfb1/a11efcdd083031e2?lnk=st&q=xul+function+prototype+group%3Anetscape.*&rnum=3&hl=en#a11efcdd083031e2 http://groups.google.com/group/netscape.public.mozilla.jseng/browse_thread/thread/89864da5f416b06a/5ca35cfd850cc006?lnk=st&q=xul+function+prototype+group%3Anetscape.*&rnum=1&hl=en#5ca35cfd850cc006 The bug: https://bugzilla.mozilla.org/show_bug.cgi?id=300079 Which means I''ll probably be making my own XUL-friendly prototype.js...fun. -Steve On 1/28/06, Steve Conover <sconover-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi everyone, > > I was playing around with xul + prototype, and everything seemed to be > going well until I ran into a wall - there seems to be some problem I > can''t explain with Function.prototype.bind, for instance when I run > this code: > > try { > new Ajax.Request("http://localhost:3000/search/hello", { > onComplete: this.onHelloComplete.bind(this) > }); > } catch (e) { > alert(e); > } > > I get an exception printed that says "TypeError: > this.onHelloComplete.bind is not a function". I''ve done some more > experimenting and confirmed that my functions just don''t have bind > methods. > > I''m a little fuzzy on the more advanced aspects of javascript like > this: can someone more knowledgable please give me a brief explanation > about why "bind" works? In other words, how is it that > Function.prototype.bind is available on every function object? I > can''t get my head wrapped around the "bind" implementation... > > And if anyone has more direct ideas on what the problem could be (why > it''s not working in the xul environment specifically), I''d love to > hear them. > > Thanks, > Steve >
Steve Conover
2006-Jan-30 15:38 UTC
Re: problem with xul/prototype experiment: "bind" method not found
Attached is my inital go at making prototype safe in XUL. If anyone has any followup questions or (later on) wants to get ahold of my latest prototype.js for XUL, email me. What I''ve done to get prototype to work is change bind from a prototype method to a freestanding function that takes the necessary params. Decidedly unsexy, but it works (so far). Regards, Steve On 1/29/06, Steve Conover <sconover-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Just for the record, I figured out the problem. There is a bug in the > XUL JS engine (going WAY back) that prevents methods from being added > dynamically to Function or RegExp. Apparently other classes should be > ok. > > References: > > http://groups.google.com/group/netscape.public.mozilla.jseng/browse_thread/thread/333a37784e94bfb1/a11efcdd083031e2?lnk=st&q=xul+function+prototype+group%3Anetscape.*&rnum=3&hl=en#a11efcdd083031e2 > > http://groups.google.com/group/netscape.public.mozilla.jseng/browse_thread/thread/89864da5f416b06a/5ca35cfd850cc006?lnk=st&q=xul+function+prototype+group%3Anetscape.*&rnum=1&hl=en#5ca35cfd850cc006 > > The bug: > > https://bugzilla.mozilla.org/show_bug.cgi?id=300079 > > > Which means I''ll probably be making my own XUL-friendly prototype.js...fun. > > -Steve > > On 1/28/06, Steve Conover <sconover-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > Hi everyone, > > > > I was playing around with xul + prototype, and everything seemed to be > > going well until I ran into a wall - there seems to be some problem I > > can''t explain with Function.prototype.bind, for instance when I run > > this code: > > > > try { > > new Ajax.Request("http://localhost:3000/search/hello", { > > onComplete: this.onHelloComplete.bind(this) > > }); > > } catch (e) { > > alert(e); > > } > > > > I get an exception printed that says "TypeError: > > this.onHelloComplete.bind is not a function". I''ve done some more > > experimenting and confirmed that my functions just don''t have bind > > methods. > > > > I''m a little fuzzy on the more advanced aspects of javascript like > > this: can someone more knowledgable please give me a brief explanation > > about why "bind" works? In other words, how is it that > > Function.prototype.bind is available on every function object? I > > can''t get my head wrapped around the "bind" implementation... > > > > And if anyone has more direct ideas on what the problem could be (why > > it''s not working in the xul environment specifically), I''d love to > > hear them. > > > > Thanks, > > Steve > > >_______________________________________________ Rails-spinoffs mailing list Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs