这两种函数语法类型有什么区别 [英] What is the difference between these 2 function syntax types
本文介绍了这两种函数语法类型有什么区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
正如标题所说,
MyFunction = function() {
}
和
function MyFunction() {
}
什么都没有?
重复: var functionName = function(){} vs function functionName(){}
推荐答案
第一种形式实际上是一个赋值给它的匿名函数的变量,第二种形式是声明函数。
The first form is actually a variable with an anonymous function assigned to it, the second is a declared function.
他们几乎可以互换,但有一些不同之处:调试器使用anons会更难(因为他们没有名字)和JS引擎可以直接访问脚本中存在的声明函数,但是在分配之后才能访问它们。
They're almost interchangeable, but have some differences: debuggers have a harder time with anons (because they lack a name) and the JS engine can directly access declared functions wherever they exist in the script, but anons can't be accessed until they have been assigned.
这篇关于这两种函数语法类型有什么区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文