Note function of js

2017-07-28  本文已影响0人  风吹过的夏天lee

All functions, in JavaScript, are first-class: They can coexist with, and can be treated like, any other JavaScript object

Anonymous functions are typically used in cases where you wish to create a function for later use

function isNimble(){ return true; }

var canFly = function(){ return true; };

window.isDeadly = function(){ return true; };

1, anonymous storing it as a property to an object

var obj = {

      someMethod: function(){

              return true;

             }    };

2 use anonymous as a callback

setInterval(function(){

         // An anonymous function called every 100 milliseconds

     }, 100);

3 recursion for anonymous

var ninja = {

       yell: function(n){

       return n > 0 ? ninja.yell(n-1) + "a" : "hiy";

} };

上一篇 下一篇

猜你喜欢

热点阅读