gpt4 book ai didi

javascript - `Function` 创建的这些函数有什么区别?

转载 作者:数据小太阳 更新时间:2023-10-29 06:06:04 26 4
gpt4 key购买 nike

1.var f = new Function("a", "b", "return a+b")

2.var f2 = Function("a", "b", "return a+b")

ff2 都是匿名函数。 f(1,2)f2(1,2) 都返回 3。那么两者之间有什么实际的内部差异吗?Function 是否在内部返回一个函数对象?与使用 Function 作为构造函数new Function(...) 的区别?

最佳答案

来自ECMAScript 5.1 specs :

When Function is called as a function rather than as a constructor, it creates and initialises a new Function object. Thus the function call Function(…) is equivalent to the object creation expression new Function(…) with the same arguments.

关于javascript - `Function` 创建的这些函数有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31257378/

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