0

Possible Duplicate:
What does ':' do in JavaScript?

I'm trying to learn jQuery and I noticed the following syntax in someone's code. It would be great if some one can explain it to me.

functionName: function(form, callback)
    {   
        form.submit(function(event) {
            event.preventDefault();
            callback(TestPageUtils.getFormParams(form));
            return false;
        });
    }
Community
  • 1
  • 1
user1558274
  • 39
  • 1
  • 1
  • 3
  • 1
    Back to the basics. I suggest you start with JavaScript, and then go to jQuery, a whole different world! – elclanrs Aug 08 '12 at 22:45
  • @user1558274 - Actually, jQuery is a perfectly appropriate place to start. It's a great way to just "get stuff done" (by not having to dwell on low level details and/or reinvent the wheel), studying jQuery is also a great way to learn "good style". I think you're doing the right thing. IMHO... – paulsm4 Aug 08 '12 at 22:50

3 Answers3

9

The syntax { property: value } is standard JavaScript notation.

At the left hand of your colon is the property name, in your case "functionName", at the right hand is its value, in your case a function definition.

These functions, then, are comma separated:

var obj = { x: 1, f: function(a) { alert(a); } };

alert(obj.x) // alerts 1
obj.f(1)     // alerts 1
David Hedlund
  • 128,221
  • 31
  • 203
  • 222
2

That's "not" jQuery, but general Javascript syntax. And that is how you define a member inside an object literal, in this case, that member is a function.

For example:

person = 
{
    name: "John",
    age: 432,
    walk: function (){alert("Walking!");}
}

Is another Javascript object. To access its members, simply do person.name. Or, if you want the person to walk, call its walk method like this: person.walk().

corazza
  • 31,222
  • 37
  • 115
  • 186
0

that's not "jQuery" per se - it's basic Javascript syntax.

The ":" says the property "functionName" has the value function(...) { ... }

Here's a good diagram (the same construct is often used in JSON syntax):

http://www.json.org/

paulsm4
  • 114,292
  • 17
  • 138
  • 190