没有函数或json的JavaScript花括号 [英] JavaScript curly braces with no function or json

查看:123
本文介绍了没有函数或json的JavaScript花括号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

刚刚打开了客户端的javascript文件,第一行是这样的:

Just opened a client's javascript file and the first lines are along the lines of this:

{
    var s_account="blog";
}

我得不到。通常,根据我的经验,花括号缠绕一个函数...

Which I don't get. Normally, in my experience, curly braces wrap around a function...

function welcome(){ ...

...或 json JavaScript 对象

var attributes = { this : "that...

任何人都可以告诉我为什么在他们之前或之后没有文字的花括号?它做什么/有什么意义?

Can anyone tell me why there are curly braces with no text before them or after them? What does it do / what is the point of it?

推荐答案


任何人都可以告诉我为什么在他们之前或之后没有文字的花括号?它做什么/什么是它是什么?

Can anyone tell me why there are curly braces with no text before them or after them? What does it do / what is the point of it?

在Javascript中它们没有重要意义。它的行为与代码只是

There is no significant point to them in Javascript. It will act exactly the same as if the code was just

var  s_account="blog";



猜测

在其他具有块范围的语言中,这可能会限制变量的范围,但由于JS没有该功能(无论好坏),没有控制结构或功能的大括号基本上没有意义并被忽略。

Speculation

In other languages which have block scope, this might restrict the scope of the variable, but since JS doesn't have that feature (for better or worse), braces without a control structure or function are essentially meaningless and ignored.

很可能这段代码是从已删除的函数中遗留下来的,或者是但是声明。它绝对不是一个可以复制的模式。

Most likely this code was left over from a deleted function or if statement however. It definitely is not a pattern to be copied.

这篇关于没有函数或json的JavaScript花括号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆