var foo = { bar : 'hello'};
var cats = happy ? "yes" : "no";
outer_loop: for(i=0; i<3; i++)
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
Functions of the colon(:) A colon is used to represent an indented block. Another major use of the colon is slicing. In slicing, the programmer specifies the starting index and the ending index and separates them using a colon which is the general syntax of slicing.
The type syntax for declaring a variable in TypeScript is to include a colon (:) after the variable name, followed by its type. Just as in JavaScript, we use the var keyword to declare a variable. Declare its type and value in one statement.
$ is simply a valid JavaScript identifier. JavaScript allows upper and lower letters, numbers, and $ and _ . The $ was intended to be used for machine-generated variables (such as $0001 ). Prototype, jQuery, and most javascript libraries use the $ as the primary base object (or function).
The conditional (ternary) operator is the only JavaScript operator that takes three operands: a condition followed by a question mark ( ? ), then an expression to execute if the condition is truthy followed by a colon ( : ), and finally the expression to execute if the condition is falsy.
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?
These are labels. Usually they are used to break out of several nested loops at once.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With