Take the example:
$.ajax({lhs:val});
What does the {}
do? As far as I know, there's no named parameters -- so is this an actual member (same as $.ajax.lhs
)? What does it mean and what does it do?
Take the example:
$.ajax({lhs:val});
What does the {}
do? As far as I know, there's no named parameters -- so is this an actual member (same as $.ajax.lhs
)? What does it mean and what does it do?
4 Answers
Reset to default 7That is object literal notation. It is creating an object with a lhs
property, set to val
.
It is another way to do the following
var obj = new Object();
obj.lhs = val;
$.ajax(obj);
In jQuery, many functions take an options object, which is just a plain object with various properties set to determine how the function acts.
It's a literal for an object.
var anObject = { member1: "Apple",
member2: function() { alert("Hello"); } };
alert(anObject.member1); // Apple
anObject.member2(); // Hello
That is an object literal (better know as a JSON object):
JSON (JavaScript Object Notation) is a lightweight data-interchange format. It is easy for humans to read and write. It is easy for machines to parse and generate. It is based on a subset of the JavaScript Programming Language, Standard ECMA-262 3rd Edition - December 1999. JSON is a text format that is pletely language independent but uses conventions that are familiar to programmers of the C-family of languages, including C, C++, C#, Java, JavaScript, Perl, Python, and many others. These properties make JSON an ideal data-interchange language.
It's an anonymous object literal. In a basic sense, think of it as an associative array that uses "words" instead of number indexes.
In your case, you're submitting that object as the first (and only) parameter of the ajax method.