6
  1. Assign object literal properties var foo = { bar : 'hello'};
  2. Ternary var cats = happy ? "yes" : "no";
  3. Label a statement outer_loop: for(i=0; i<3; i++)
  4. What else?

I'm poking through a sharepoint 2010 file and I keep running into this syntax

someFunction: ;

For instance, there is a file where the following function is declared near the top:

function ULSqvN() {
    var o = new Object;
    o.ULSTeamName = "SharePoint Portal Server";
    o.ULSFileName = "SocialData.js";
    return o;
}

and then later in the file we find the following

PageUrlNormalizer = function () {
    ULSqvN: ; //<---------------- This guy here --------------------------
    try {
        this._url = _normalizedPageUrlForSocialItem
    } catch (a) {
        this._url = ""
    }
};

What is this doing?

jsFiddle with full file. This same ULSqvN: ; occurs 47 times in the file.

edit: Added full code.

PS: Consensus seems to be that the sharepoint use of colon is "not actual javascript, possibly used as a marker for some external purpose". The browser sees it as a vestigial label and so causes no errors. Thanks for all the replies, I have left the actual uses at the top so that the question contains the appropriate answers. question about same code

Community
  • 1
  • 1
Sinetheta
  • 9,189
  • 5
  • 31
  • 52
  • Your jsFiddle link is just pointing to jsfiddle.com. – ThinkingStiff Jan 20 '12 at 19:31
  • You point it out yourself: it's a label. It is likely automatically generated by the obfuscator (but I don't have a reason as for "why"). And, as always, the awful atrocity that is MS JS is showing it's ugly head... ever take a look at the Communicator stuff? :) –  Jan 20 '12 at 19:38
  • A label defined like that can't be used. It will be `undefined` after the semicolon: http://jsfiddle.net/ThinkingStiff/3F7UY/. The only other use I could think of is a tracing or debugging tool, or perhaps unit testing. Maybe the coder was using them as comments?! – ThinkingStiff Jan 20 '12 at 19:41
  • @Sinetheta Would a *sane* programmer use "ULSqvN"? The SP stuff has a *bunch* of mangling (with even more cryptic names in places), so yes, there is likely a processing tool being applied. –  Jan 20 '12 at 19:42
  • @ThinkingStiff lol, thanks. Although that would be hilarious, it wouldn't be the saddest thing I've found baked into Sharepoint. – Sinetheta Jan 20 '12 at 19:43

4 Answers4

8

It has no purpose javascript-wise (since in javascript you would only label something that you can continue or break), it might be used as a some kind of comment or marker for some parsing script. At worst it's just dead code with no purpose whatsoever.

Edit: looks like sharepoint uses it for some diagnostic information: What does this Javascript code do?

Community
  • 1
  • 1
Esailija
  • 138,174
  • 23
  • 272
  • 326
  • You win the check-mark unless someone can figure out a use for this code. – Sinetheta Jan 20 '12 at 19:44
  • @Sinetheta I have clarified the "marker for some parsing script" part :D The point about being completely dead code for javascript itself still holds though – Esailija Jan 20 '12 at 19:47
  • thanks for finding that question "What does this Javascript code do?" wasn't my first search when I went looking for answers ;) – Sinetheta Jan 20 '12 at 20:52
3

These are labels. Usually they are used to break out of several nested loops at once.

Example

function foo ()
{
    dance:
    for(var k = 0; k < 4; k++){
        for(var m = 0; m < 4; m++){
            if(m == 2){
                break dance;
            }
        }
    }
}

Credit: this answer.

Community
  • 1
  • 1
Sergio Tulentsev
  • 226,338
  • 43
  • 373
  • 367
  • sorry, I should have included more code. Shouldn't a label immediately proceed a loop of some kind? Mine is just hanging out on its lonely, immediately followed by a semi-colon – Sinetheta Jan 20 '12 at 19:22
  • @Sinetheta: yeah, that doesn't make sense. Maybe it's just abandoned code? :) – Sergio Tulentsev Jan 20 '12 at 19:23
  • Wouldn't that function the same way if `dance:` had a semicolon after it? Maybe the coder of the OPs code didn't know any better. – ThinkingStiff Jan 20 '12 at 19:34
  • @ThinkingStiff Since this is a source file from sharepoint 2010 I'm really hoping it's valid useful js – Sinetheta Jan 20 '12 at 19:37
  • @Sinetheta Wow, I was wrong. It's actually broken: http://jsfiddle.net/ThinkingStiff/3F7UY/. `Uncaught SyntaxError: Undefined label 'dance'`. After the semicolon it can't be used. – ThinkingStiff Jan 20 '12 at 19:39
2

It is am empty label, and then an empty statement. (I can't see any good reason for this - unless there is something later in the function that wasn't included here, that needs the label to break out of a loop within that function.)

ziesemer
  • 27,712
  • 8
  • 86
  • 94
1

The third usage is to label a statement for use with a break or continue statement. See the spec.

Larry K
  • 47,808
  • 15
  • 87
  • 140
  • thanks, forgot to include that. Still trying to figure out what's going on in this file though. It's straight from Sharepoint 2010 so I'm assuming it does something useful. – Sinetheta Jan 20 '12 at 19:30