Using colon in javascript

  • Assigning object literal properties var foo = { bar : 'hello'};
  • Ternar var cats = happy ? "yes" : "no"; var cats = happy ? "yes" : "no";
  • Denote the outer_loop: for(i=0; i<3; i++) operator outer_loop: for(i=0; i<3; i++)
  • What else?

I am scrolling through a sharepoint 2010 file and I continue to work in this syntax

 someFunction: ; 

For example, there is a file in which the following function is declared at the top:

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

and then in the file we find the following

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

What does it do?

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

edit: Added full code.

PS: The consensus seems to be that using a colon sharepoint is "not actual javascript, maybe used as a marker for some external purpose." The browser sees this as a rudimentary label and therefore does not cause errors. Thanks for all the answers, I left the actual use at the top so that the question contains the corresponding answers. question about the same code

+6
source share
4 answers

It has no purpose javascript-wise (since in javascript you would only write something that you can continue or break up ), it can be used as some comment or marker for some parsing of the script. In the worst case, it is just dead code with no purpose.

Edit: sharepoint seems to be using it for some diagnostic information: What does this Javascript code do?

+8
source

These are tags. 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 .

+3
source

This is an empty label, and then an empty statement. (I see no good reason for this - if there is something else in the function that was not included here that requires the label to break out of the loop inside this function.)

+2
source

The third use is the instruction label for use with the break or continue statement. See specification

+1
source

Source: https://habr.com/ru/post/906502/


All Articles