{} is an object designation in JavaScript. For example:
$('selector').plugin({ option1: 'value' });
In this case, you pass the object containing your settings to the plugin. A plugin can consider this as an object, regardless of what it refers to, for example:
settings.option1
Of course, it has many more uses, but this is the most common example in jQuery. The same is true for .animate() , $.ajax() , .css() , etc. Anything that accepts properties usually uses this format.
As requested, some other examples:
Any object inside the transferred object can also be a function, and not just properties, for example:
$("<input>", { type: "text", focusin: function() { alert("Hi, you focused me!"); } });
This would set the focal event of this input to alert. Another is the extension of an object, adding properties to it, for example:
var person = { first_name: "John" }; $.extend(person, { last_name: "Smith" }); //equivalent to: person.last_name = "Smith"; //or: person["last_name"] = "Smith";
Now person has the last_name property. This is also often used by plugins to use the default settings, then combine all the parameters that you passed, overwrite with any parameters that you specified, using the default values ββfor the rest.
Why do we use it? Well ... the way javascript works, and in jQuery style: this is an extremely accurate and flexible way to convey information.
Nick Craver Apr 07 2018-10-18T00: 00Z
source share