在javascript中声明和定义函数(declaring and defining functions in javascript)

系统教程 行业动态 更新时间:2024-06-14 16:57:40
在javascript中声明和定义函数(declaring and defining functions in javascript)

我对javascript中的函数(对象)有疑问。 我有两段代码,比如

var a= function(){ console.log('abc') }

var a= (function(){ console.log('abc') })

这两者有什么区别>> 感谢名单:)

I have a doubt regarding functions(objects) in javascript. I have 2 pieces of code like,

var a= function(){ console.log('abc') }

and

var a= (function(){ console.log('abc') })

what is the difference between these two>> thanx:)

最满意答案

没有实际的区别。 它们都会导致将匿名函数分配给a 。

第一个是“ 简单的任务 ”。 在第二个中,括号充当“ 分组运算符 ”,它做了一件事:

生产PrimaryExpression:(Expression)的计算方法如下:

返回评估Expression的结果。 这可以是参考类型。

因此,分组运算符将返回其中包含的函数,并将其分配给a ,就像第一个示例一样。

There is no practical difference. They will both result in an anonymous function being assigned to a.

The first is a "simple assignment". In the second, the parentheses are acting as a "grouping operator", which does one thing:

The production PrimaryExpression : ( Expression ) is evaluated as follows:

Return the result of evaluating Expression. This may be of type Reference.

So the grouping operator will return the function contained within it, and assign it to a, just like the first example.

更多推荐

本文发布于:2023-04-13 12:31:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/dzcp/5b6b594d65ad605a97e3bb66ea1ec43c.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:函数   定义   声明   javascript   defining

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!