tag:blogger.com,1999:blog-19002723.post132898885141640070..comments2023-02-21T00:14:00.325-08:00Comments on Tagneto: Defining $ for Dojo and setting a function prototypeJameshttp://www.blogger.com/profile/12067100302830600925noreply@blogger.comBlogger9125tag:blogger.com,1999:blog-19002723.post-37023092486750531922008-05-27T22:23:00.000-07:002008-05-27T22:23:00.000-07:00James,setting non-standard __proto__ is quite simp...James,<BR/>setting non-standard __proto__ is quite simple. All you need is to use a "proxy" constructor (which Crockford advertises as a Object.beget method):<BR/><BR/>function F(){}<BR/>F.prototype = bar;<BR/>foo = new F;<BR/><BR/>// in Mozilla the following will be true<BR/>foo.__proto__ == bar;Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-19002723.post-28809440666440675862007-12-04T13:19:00.000-08:002007-12-04T13:19:00.000-08:00pottedmeat: very nice. It did not occur to me to r...pottedmeat: very nice. It did not occur to me to replace the original object with a modified one.<BR/><BR/>I liked the idea of modifying the prototype for $, but the mixin and replace solution is nice and can work in a generic case. It can even be collapsed down to a one-liner, so bonus points for that.Jameshttps://www.blogger.com/profile/12067100302830600925noreply@blogger.comtag:blogger.com,1999:blog-19002723.post-15803184372988222052007-12-04T11:13:00.000-08:002007-12-04T11:13:00.000-08:00$ = dojo = dojo.mixin(function(){ return dojo.que...$ = dojo = dojo.mixin(function(){<BR/> return dojo.query.apply(dojo, arguments);<BR/>}, dojo);<BR/><BR/>// And test<BR/>$.addOnLoad(function(){<BR/> console.debug($("div"));<BR/>});Anonymoushttps://www.blogger.com/profile/13970223630576232100noreply@blogger.comtag:blogger.com,1999:blog-19002723.post-32348779380992447662007-12-04T09:23:00.000-08:002007-12-04T09:23:00.000-08:00shaneosullivan: oops, I did not address your secon...shaneosullivan: oops, I did not address your second post: setting $.prototype will not work in that case, since $ is already created.<BR/><BR/>Setting $.prototype would only help things that use $ in their prototype chain (as I understand it).<BR/><BR/>And for what it is worth, I did try an example like that, but it did not work.<BR/><BR/>What I really want to do in that line is something like $.__proto__ = dojo, but I consider that verboten, and does not work cross browser.Jameshttps://www.blogger.com/profile/12067100302830600925noreply@blogger.comtag:blogger.com,1999:blog-19002723.post-85830536437602389242007-12-04T09:17:00.000-08:002007-12-04T09:17:00.000-08:00shaneosullivan: I see two issues with that approac...shaneosullivan: I see two issues with that approach:<BR/><BR/>1) The dojo module loader attaches properties directly to the dojo object, not on dojo.prototype.<BR/><BR/>2) I also do not want to modify the Function.prototype since that will affect all Function derivatives. I did that in my example code above, just to see if it would work, but I would not want that change for the "final" solution.Jameshttps://www.blogger.com/profile/12067100302830600925noreply@blogger.comtag:blogger.com,1999:blog-19002723.post-164664961193271252007-12-04T02:41:00.000-08:002007-12-04T02:41:00.000-08:00Sorry, I meant:$ = new Function("return dojo.query...Sorry, I meant:<BR/>$ = new Function("return dojo.query.apply(dojo, arguments);");<BR/>$.prototype = dojo.prototype;<BR/><BR/>ShaneAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-19002723.post-12328198571253471162007-12-04T01:42:00.000-08:002007-12-04T01:42:00.000-08:00Instead of:Function.prototype = dojo;$ = new Funct...Instead of:<BR/>Function.prototype = dojo;<BR/>$ = new Function("return dojo.query.apply(dojo, arguments);");<BR/><BR/>try:<BR/><BR/>$ = new Function("return dojo.query.apply(dojo, arguments);");<BR/>Function.prototype = dojo.prototype;<BR/><BR/>Then anything added to the dojo's prototype will automatically be added to $'s prototypeAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-19002723.post-82025599489211189322007-12-03T18:31:00.000-08:002007-12-03T18:31:00.000-08:00pottedmeat: That would solve the immediate example...pottedmeat: That would solve the immediate example for Dojo, but I am interested in a general technique, something that could be added after the fact, without requiring internal Dojo code changes.<BR/><BR/>It seemed like an interesting thought exercise on functions and prototypes. I do not see a generic way of getting the result I want, but maybe someone else has an idea.Jameshttps://www.blogger.com/profile/12067100302830600925noreply@blogger.comtag:blogger.com,1999:blog-19002723.post-82236436827041557442007-12-03T17:34:00.000-08:002007-12-03T17:34:00.000-08:00So, really simply: We just add the ability to have...So, really simply: We just add the ability to have something like djConfig.dojo that lets you define what "dojo" is created as. By default, it's {}. So you make it use a function instead, and have a pointer from $ to dojo.Anonymoushttps://www.blogger.com/profile/13970223630576232100noreply@blogger.com