Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What do { and } mean inside params?

Tags:

javascript

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?

like image 842
An employee Avatar asked Nov 26 '25 23:11

An employee


2 Answers

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.

like image 55
bdukes Avatar answered Nov 28 '25 12:11

bdukes


It's a literal for an object.

var anObject = { member1: "Apple",
                 member2: function() { alert("Hello"); } };

alert(anObject.member1);      // Apple
anObject.member2();           // Hello
like image 38
Georg Schölly Avatar answered Nov 28 '25 12:11

Georg Schölly



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!