首页 > 其他 > 详细

自执行匿名函数语法和普通函数语法对比

时间:2015-04-13 01:37:08      阅读:201      评论:0      收藏:0      [点我收藏+]
var eatFunction = function (what_to_eat) {
  var sentence = ‘I am going to eat a ‘ + what_to_eat;
  console.log( sentence );
};
eatFunction( ‘sandwich‘ );

// is the same as

(function (what_to_eat) {
  var sentence = ‘I am going to eat a ‘ + what_to_eat;
  console.log(sentence);
})(‘sandwich‘);

// is the same as

(function (what_to_eat) {
  var sentence = ‘I am going to eat a ‘ + what_to_eat;
  console.log(sentence);
}(‘sandwich‘)); 

// Three of them output ‘I am going to eat a sandwich‘

  唯一的区别是,变量 eatFunction 被移除了,使用一对括号把函数定义包了起来。

自执行匿名函数语法和普通函数语法对比

原文:http://www.cnblogs.com/nodejsxxh/p/4421137.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!