Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #26289
| Date | 2014-12-09 23:15 +1000 |
|---|---|
| From | RobG <rgqld@iinet.net.au> |
| Newsgroups | comp.lang.javascript |
| Subject | Re: Beginner's question: How does this function definition work? |
| References | <6fae7412-601f-4fda-8739-35cc865cc36d@googlegroups.com> <20141111222613.2d818647@cel.eternal-september.org> |
| Message-ID | <fv2dnYIrgd5_aBvJnZ2dnUU7-TOdnZ2d@westnet.com.au> (permalink) |
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
Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Beginner's question: How does this function definition work? twgray2007@gmail.com - 2014-11-10 21:54 -0800
Re: Beginner's question: How does this function definition work? Charles Lehner <est.cel@celehner.com> - 2014-11-11 22:26 -0500
Re: Beginner's question: How does this function definition work? RobG <rgqld@iinet.net.au> - 2014-12-09 23:15 +1000
Re: Beginner's question: How does this function definition work? cezary.tomczyk@gmail.com - 2014-12-09 13:43 -0800
Re: Beginner's question: How does this function definition work? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-12-09 17:59 +0100
csiph-web