2

The following code is extracted from SharePoint's SP.UserProfiles.debug.js library.

    getUserProfilePropertiesFor: function (d) {
    a: ;
    var b = this.get_context(),
    a,
    c = new SP.ClientActionInvokeMethod(this, "GetUserProfilePropertiesFor", [d]);
    b.addQuery(c);
    a = [];
    b.addQueryIdAndResultObject(c.get_id(), a);
    return a
}

What does the "a: ;" on second line mean? When I step-through in IE Developer tool, that line was skipped right through. But it also does not look like a label as it has a semi-colon at the end.

Conax
  • 37
  • 5
  • Huh, I'd never seen this before, but apparently it can be [used to label a statement](https://stackoverflow.com/questions/418799/what-does-colon-do-in-javascript#418865)... Here's some more about it on [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/label). – Alexander Nied Aug 02 '17 at 02:18
  • 2
    Why would a semi-colon mean that it was not a label? It's a label on an empty statement. –  Aug 02 '17 at 02:23
  • @torazaburo He probably meant "variable" – slebetman Aug 02 '17 at 02:29
  • At first I thought it was minified code and some kind of marker for the minification. But then I saw it came from a file ending in `*.debug.js` and was horrified to think that was unminified code! Dear gods tell me they don't actually code their variable names like that! – Sukima Aug 02 '17 at 02:46
  • @Sukima, that's SharePoint out of box JavaScript library. – Conax Aug 02 '17 at 02:56
  • That is some terrible code - maybe some tool generated it? – John Hascall Aug 02 '17 at 03:02
  • I've never used labels in JavaScript before and today it's the first time I see something like this, I did Google a bit and see the possibility that can be a label. But nowhere in that little function require the use of that label, plus a few more lines later there is a = [];. Also this is just one of the many functions in that script library that has this kind of code. So I thought maybe it's something other than a label. Besides, all the JavaScript label example I've found uses label to break out loops. I don't see why there should need a label in this function. – Conax Aug 02 '17 at 03:04
  • @John Hascall, yes it does look ugly. But I don't think they expect SharePoint users (even developers) to dig out their code. Generally people uses MSDN to find the methods they can use. I just opened this file out of interest. – Conax Aug 02 '17 at 03:09

1 Answers1

3

What does the "a: ;" on second line mean?

It is a label statement : https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/label

basarat
  • 207,493
  • 46
  • 386
  • 462