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

5
  • Your jsFiddle link is just pointing to jsfiddle.com. Commented Jan 20, 2012 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? :) Commented Jan 20, 2012 at 19:38
  • A label defined like that can't be used. It will be undefined after the semicolon: 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?! Commented Jan 20, 2012 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. Commented Jan 20, 2012 at 19:42
  • @ThinkingStiff lol, thanks. Although that would be hilarious, it wouldn't be the saddest thing I've found baked into Sharepoint. Commented Jan 20, 2012 at 19:43

4 Answers 4

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?

Sign up to request clarification or add additional context in comments.

3 Comments

You win the check-mark unless someone can figure out a use for this code.
@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
thanks for finding that question "What does this Javascript code do?" wasn't my first search when I went looking for answers ;)
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.

5 Comments

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: yeah, that doesn't make sense. Maybe it's just abandoned code? :)
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 Since this is a source file from sharepoint 2010 I'm really hoping it's valid useful js
@Sinetheta Wow, I was wrong. It's actually broken: jsfiddle.net/ThinkingStiff/3F7UY. Uncaught SyntaxError: Undefined label 'dance'. After the semicolon it can't be used.
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.)

3 Comments

And the label name just happens to be the name of a function?
@Sinetheta - Yes. This doesn't make any sense to me. The script would execute the same both with and without the labels.
Thanks for your reply, sounds like that is the consensus
1

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

1 Comment

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.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.