job立刻执行_立即执行功能

job立刻执行

JavaScript is full of nifty little tricks to accomplish tasks with less code.  One of those tricks is immediately executing functions.  We oftentimes see this pattern for executing anonymous functions to limit variable scope:

JavaScript充满了漂亮的小技巧,可以用更少的代码来完成任务。 这些技巧之一就是立即执行功能。 我们经常看到这种执行匿名函数以限制变量范围的模式:


(function() {
	console.log('executed!');

	// Do processing here

})();


What many developers don't know is that this code can be shorted by using a ! before the anonymous function:

许多开发人员不知道的是,可以使用!来缩短此代码! 在匿名函数之前:


!function() {
	console.log('executed!');

	// Do processing here	
}()


The function above executes immediately, just as the first snippet did.  One caveat:  the immediately executing function always returns false.  If you desire the result of the anonymous function, you wont want to use this second pattern.

上面的功能会立即执行,就像第一个代码片段一样。 一个警告:立即执行的函数始终返回false 。 如果需要匿名函数的结果,则不想使用第二种模式。

Ben Alman has created an excellent, detailed writeup on the subject and if you want to learn more, be sure to visit his post!

本·阿尔曼(Ben Alman)为此主题撰写了一篇出色,详尽的文章,如果您想了解更多信息,请务必访问他的帖子!

翻译自: https://davidwalsh.name/immediately-executing-functions

job立刻执行

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值