RobG
12/9/2014 1:15:00 PM
On 12/11/2014 1:26 pm, Charles Lehner wrote:
> On Mon, 10 Nov 2014 21:54:50 -0800 (PST) twgray2007@gmail.com wrote:
>
>> "init" : function init(x, y, settings) { this.value = 1000;
>> this.parent(x, y, settings); }
>>
>> I just don't get it. I know : is equivalent to '='., so is it same
>> as:
>>
>> var init = function(x, y, settings) ?
>>
>
> In this case : is used only when defining a property in an object
> literal. This is often used with functions when creating a prototype
> object, e.g.:
>
> Thing.prototype = { init: function() { /* ... */ } };
>
> Using = assigns the function value to a variable, rather than as a
> property of an object.
>
> If defining a function with a colon not in an object literal doesn't
> produce an error, then it is actually getting parsed as a label,
> which is an unrelated, obscure feature of the language having to do
> with switch statements.
Speaking of obscure features, I stumbled across a script file called
sp.ui.rte.js in SharePoint (it's over 14,000 lines of code) that starts
with:
function ULSNVe() {
...
}
Then every function expression and declaration thereafter contains, at
the top, the statement:
ULSNVe: ;
which would seem to be a label. I can't fathom why anyone would do that.
--
Rob