Too much recursion 

Higher Order Javascript

 



   Subscribe in NewsGator Online    Subscribe in Rojo    Add to Google      Add to My AOL   Subscribe in FeedLounge   Add to netvibes  

Brendan Eich's Roadmap  Standard ECMA-262  www.schillmania.com  www.quirksmode.org 
www.snook.ca  www.davidflanagan.com  www.kryogenix.org  www.thomasfrank.se 
www.dustindiaz.com  Yahoo! UI Library  www.crockford.com  www.brainjacked.com 
chadlindstrom.ca  www.browserland.org     
       

Tuesday, July 18, 2006

 

Function Fun


Here I'll post some small functions. Hopefully a few will give you a smile :)
myFun=function(){
var me=arguments.callee;
me.browser= (document.all)
? function(){alert("Hi I'm IE")} : function(){alert("Hi I'm FireFox")};
myFun=function(myFun){
arguments.callee.caller.browser();
alert(myFun);
}
myFun(myFun);
}();
This function at first glance exhibits some strange behaviour. Not the fact that it tests for document.all ;), but the result of alert(myFun). I thought it would have been == arguments.callee.caller, like this:
myFun=function(){
var me=arguments.callee;
me.browser= (document.all)
? function(){alert("Hi I'm IE")} : function(){alert("Hi I'm FireFox")};
myFun=function(myFun){
me.browser();
alert(arguments.callee.caller+"\n~~~~~~~~~~\n"+myFun);
}
myFun(me);
}();
alert(myFun);
Result of alert(myFun): undefined... and

myFun=function(){
var me=arguments.callee;
me.browser= (document.all)
? function(){alert("Hi I'm IE")} : function(){alert("Hi I'm FireFox")};
myFun=function(){
me.browser();
alert(arguments.callee.caller+"\n~~~~~~~~~~\n"+myFun);
}
myFun(me);
}();
alert(myFun);
Result of alert(myFun): undefined... and here is an anonymous function:
new function(){
arguments[0].message();
}({message:function(){alert('called by null')}});




Comments:
Hey what a great site keep up the work its excellent.
»
 
Post a Comment

Links to this post:

Create a Link



<< Home

Archives

June 2006   July 2006   August 2006   September 2006  

This page is powered by Blogger. Isn't yours?