最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin0浏览0评论

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.

发布评论

评论列表(0)

  1. 暂无评论