Daft
Daft

Reputation: 10964

Unsure how this jQuery function works

I came across this function recently, I am unsure what the first few lines do.

Could someone possibly explain it to me?

Cheers

jQuery.extend(jQuery.ui.dialog.prototype.options, {
     create: function(event) { doSomthing(event); }
});

function doSomthing(event) {

    STUFF
}

Upvotes: 2

Views: 64

Answers (3)

David Barker
David Barker

Reputation: 14620

$.extend is a jquery function that merges objects together, overwriting any object keys with newer 'versions'.

// Will overwrite the name property. Output in this case is 'john'
// as it overwrites 'dave'
$.extend({name : "dave"}, {name : 'john'});

In the case of the example code you gave, $.extend is overwriting a prototype object in a jQueryUI dialog widget with a different function, thus changing how the 'dialog' widget behaves when it is created.

Upvotes: 3

Feanor
Feanor

Reputation: 3690

It binds call of doSomthing to the create event of the jQuery.ui.dialog or the jQuery.ui.dialog.prototype.options.

So doSomthing might be called when you create dialog or option. Not sure if creation of the option is implemented.

Upvotes: 1

Alex
Alex

Reputation: 11245

  1. jQuery.extend - Merge the contents of two or more objects together into the first object.
  2. jQuery.ui.dialog.prototype.options is shared field options for all ui dialogs. More info about prototype inheritance here.

Upvotes: 3

Related Questions