Defining Functions


What ways can we define functions?
 function isNimble(){ return true; } 
 var canFly = function(){ return true; }; 
 window.isDeadly = function(){ return true; }; 
 log(isNimble, canFly, isDeadly); 

Does the order of function definition matter?
 var canFly = function(){ return true; }; 
 window.isDeadly = function(){ return true; }; 
 assert( isNimble() && canFly() && isDeadly(), "Still works, even though isNimble is moved." ); 
 function isNimble(){ return true; } 

Where can assignments be accessed?
 assert( typeof canFly == "undefined", "canFly doesn't get that benefit." ); 
 assert( typeof isDeadly == "undefined", "Nor does isDeadly." ); 
 var canFly = function(){ return true; }; 
 window.isDeadly = function(){ return true; }; 

Can functions be defined below return statements?
 function stealthCheck(){ 
   assert( stealth(), "We'll never get below the return, but that's OK!" ); 

   return stealth();

   function stealth(){ return true; } 
 } 

 stealthCheck(); 

你可能感兴趣的:(java)