美文网首页
Note function of js

Note function of js

作者: 风吹过的夏天lee | 来源:发表于2017-07-28 09:46 被阅读0次

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";

} };

相关文章

网友评论

      本文标题:Note function of js

      本文链接:https://www.haomeiwen.com/subject/stlxlxtx.html