码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2015-04-13 01:39:43      阅读:117      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!