JS--匿名函数

匿名函数的应用

  (1)将一个匿名函数保存在变量中

var sayName = function(){
    console.log('sayName function');
}

  (2)将一个匿名函数保存在对象的方法中

var person = {
    sayName: function(){
        console.log('sayName');
    }
}

 

  (3)将一个匿名函数作为回调函数

setTimeout(function(){
    console.log('hello world');
}, 1000);

猜你喜欢

转载自www.cnblogs.com/marton/p/10269573.html