Why are we using ({ })?
Is it delegate?
What does it mean to use this syntax?
What are we wrapping with it?
For example:
$.ajaxSetup ({ // <-- THIS
error: fError,
compelete: fComp,
success: fSucc
}); // <-- AND THIS
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
{}is object notation in JavaScript. For example:In this case you’re passing an object containing your settings to the plugin. The plugin can deal with this as a object, whatever it’s referenced as, for example:
Of course it has a lot more uses, but this is the most common example in jQuery. The same is true for the
.animate(),$.ajax(),.css()functions, etc. Anything that takes properties generally uses this format.As requested, some other examples:
Any object inside the passed object can be a function as well, not only properties, for example:
This would set the focus event of that input to have an alert. Another is extending an object, adding properties to it, like this:
Now
personhas thelast_nameproperty. This is often used by plugins as well, to take the default settings, then merge any settings you passed in, overwriting with any settings you specified, using defaults for the rest.Why are we using it? Well…that’s how JavaScript works, and in the jQuery spirit: it’s an extremely terse and flexible way to pass information.