这个Javascript代码有什么作用? [英] What does this Javascript code do?

查看:101
本文介绍了这个Javascript代码有什么作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在看Sharepoint脚本文件,我遇到过这一点,我没有得到:

I've been looking at Sharepoint script files and I've come across this bit that I don't get:

function ULSTYE() {
    var o = new Object;
    o.ULSTeamName = "Microsoft SharePoint Foundation";
    o.ULSFileName = "SP.UI.Dialog.debug.js";

    return o;
}

SP.UI.$create_DialogOptions = function() {
    ULSTYE:;   <----------------------------- WTF?
    return new SP.UI.DialogOptions();
}

此文件中的每个函数定义实际上都以相同的 ULSTYE:; 在开始大括号之后。任何人都可以解释第二个函数的第一行是做什么的吗?

Actually every function definition in this file starts with the same ULSTYE:; line right after the opening brace. Can anybody explain what does the first line in the second function do?

Firefox / Firebug例如将这个函数解释为我无法理解的东西:

Firefox/Firebug for instance interprets this function as something that I can't understand either:

function () {
    ULSTYE: {
    }
    return new (SP.UI.DialogOptions);
}

我以为我知道Javascript直通...... / em>;)必须是我过去从未使用的一些模糊的功能,显然很少被其他人使用。

And I thought I knew Javascript through and through... ;) Must be some obscure feature I never used in the past and is obviously seldomly used by others as well.

推荐答案

第一位定义了一个函数,该函数创建具有几个属性的对象并返回它。我想我们都清楚这一点。 : - )

The first bit defines a function that creates an object with a couple of properties and returns it. I think we're all clear on that bit. :-)

然而,第二位是不使用该功能。它定义了一个名称相同的标签。虽然它使用相同的字符序列,但是对上述函数的引用。 Firefox的解释与其他任何东西一样有意义,因为标签之后应该引用它可以引用的东西。

The second bit, though, is not using that function. It's defining a label with the same name. Although it uses the same sequence of characters, it is not a reference to the function above. Firefox's interpretation makes as much sense as anything else, because a label should be followed by something to which it can refer.

有关标签语句的更多信息,请参阅第12.12节< a href =http://www.ecma-international.org/publications/standards/Ecma-262.htm =noreferrer>规范。

For more about labelled statements, see Section 12.12 of the spec.

偏离主题:我会避免使用此来源的代码。编写它的人显然对JavaScript很新,并没有表明他们知道自己在做什么。例如,他们离开()离开新的Object()调用,虽然这是允许的,但它是相当狡猾的事情要做。他们可能会争辩说他们这样做是为了节省空间,但如果他们这样做,他们最好使用对象文字:

Off-topic: I would avoid using code from this source. Whoever wrote it is apparently fairly new to JavaScript and doesn't show much sign that they know what they're doing. For instance, they've left the () off the new Object() call, and while that's allowed, it's fairly dodgy thing to do. They could argue that they were doing it to save space, but if they were, they'd be better off using an object literal:

function ULSTYE() {
    return {
        ULSTeamName: "Microsoft SharePoint Foundation",
        ULSFileName: "SP.UI.Dialog.debug.js"
    };
}

没有太多理由写 new Object() ; {} 在功能上是相同的。

There's never much reason to write new Object() at all; {} is functionally identical.

当然,第二位根本就没有理由。 : - )

And, of course, there's no justification for the second bit at all. :-)

这篇关于这个Javascript代码有什么作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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