Sunday, May 19, 2024
 Popular · Latest · Hot · Upcoming
154
rated 0 times [  157] [ 3]  / answers: 1 / hits: 35586  / 13 Years ago, tue, february 21, 2012, 12:00:00

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?


More From » function

 Answers
3

You are missing some code there, but I assume its part of an object declaration like this:



var obj = {
queryString: function() {
//some code
}
};
obj.queryString();


It assigns a function as a property of an object literal. It would be equivalent to this:



var obj = {};
obj.queryString = function() { ... };
obj.queryString();


In general, the object literal syntax looks like this:



{ key: value, otherKey: otherValue };


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.


[#87311] Monday, February 20, 2012, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
darennevina

Total Points: 422
Total Questions: 128
Total Answers: 105

Location: Comoros
Member since Tue, Mar 14, 2023
1 Year ago
;