gpt4 book ai didi

javascript - Javascript 中的函数声明

转载 作者:行者123 更新时间:2023-11-30 07:43:51 25 4
gpt4 key购买 nike

<分区>

Possible Duplicate:
What is the difference between a function expression vs declaration in Javascript?

以这些方式声明函数之间是否存在主要区别:

  1. function foo(){
    alert('BAR');
    }
  2. var foo = function (){
    alert('BAR');
    }
  3. var foo = function bar(){
    alert('BAR');
    }

有人告诉我here那:

It happens at a different time, and results in a variable referring to an anonymous function. A function declaration happens prior to any stepwise code executing in the scope, and results in both a binding and a function with a proper name.

我声明函数的方式真的会影响代码的效率吗?如果会,哪种方式最好?

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com