javascript - What do { and } mean inside params? - Stack Overflow

Take the example:$.ajax({lhs:val});What does the {} do? As far as I know, there's no named paramet

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?

Share Improve this question edited Sep 24, 2009 at 19:13 Donut 113k20 gold badges135 silver badges147 bronze badges asked Sep 24, 2009 at 19:10 An employeeAn employee 6,3189 gold badges35 silver badges43 bronze badges
Add a ment  | 

4 Answers 4

Reset to default 7

That 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.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745284870a4620499.html

相关推荐

  • javascript - What do { and } mean inside params? - Stack Overflow

    Take the example:$.ajax({lhs:val});What does the {} do? As far as I know, there's no named paramet

    2小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信