What does this code refer too?
queryString: function() {
//some code
}
I tested it in the WebConsole (Firefox) but it wouldn't execute, so I'm thinking that it isn't equivalent to function queryString() {}
.
So what is it exactly?
What does this code refer too?
queryString: function() {
//some code
}
I tested it in the WebConsole (Firefox) but it wouldn't execute, so I'm thinking that it isn't equivalent to function queryString() {}
.
So what is it exactly?
You are missing some code there, but I assume its part of an object declaration like this:
It assigns a function as a property of an object literal. It would be equivalent to this:
In general, the object literal syntax looks like this:
So the reason this didn't work in the console is that it was not enclosed in
{}
characters, denoting an object literal. And this syntax is valid ONLY in an object literal.The
:
is used when defining an object and its properties.Now
obj.queryString
is your function.What the
means is the you can use queryString() to call the function that it refers to. This kind referencing is generally used if you want to define a class(or a pseudo class ;P) in your javascript. Something like this,
So now at anyother part of the code you can create objects for class_name and use it to access the property1,property2 etc.,
This is probably inside a map/object declaration like so:
It's a label https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/label