Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #26120
| From | Charles Lehner <est.cel@celehner.com> |
|---|---|
| Newsgroups | comp.lang.javascript |
| Subject | Re: Beginner's question: How does this function definition work? |
| Date | 2014-11-11 22:26 -0500 |
| Organization | A noiseless patient Spider |
| Message-ID | <20141111222613.2d818647@cel.eternal-september.org> (permalink) |
| References | <6fae7412-601f-4fda-8739-35cc865cc36d@googlegroups.com> |
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.
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