On 15 September 2011 14:30, Matthew Bramer <[email protected]> wrote:
> Hey guys,
> I really appreciate your time.  I'm definitely leaning towards a callback,
> because I think this will handle my other question about options.FormatData
> as well.  Here is a sample call into my module:
> ***********************************************************************
> jsllc.LoadDDL("Master List", '#NewEFM',{
> Query: "<Query><Where><Neq><FieldRef Name='ID' /><Value Type='Counter'>" +
> PID + "</Value></Neq></Where><OrderBy><FieldRef Name='EFMFullNameDDL'
> Ascending='True' /></OrderBy></Query>",
> ViewField: "EFMFullNameDDL",
> Split: true
> });
> ***********************************************************************
> I've heard of callbacks and I know I use them all over in my jQuery code,
> but to date I have not written one, nor do I understand much about them.


Here's a simple function that takes a callback:

function giveCallbackDave(callback) {
  callback('dave');
}

Then you'd call that by passing a callback:

giveCallbackDave(function (name) { alert(name); }); //alerts 'dave'

Basically, a function that takes a callback will keep a reference to
the callback, and at some point will call the callback, maybe passing
in an argument. So, with jQuery.get, the callback will be executed
after the XHR has returned. Something like $.each will call the
callback for each element of the collection. The difference is that
with .get the callback will be called asynchronously (it'll happen
sometime after the function that supplied the callback has returned)
whereas with .each it'll happen synchronously (the callback will be
called multiple times with each element before the each function
returns).

Hope that helps!

-- 
Nick Morgan
http://skilldrick.co.uk
@skilldrick

Save our in-boxes! http://emailcharter.org

-- 
To view archived discussions from the original JSMentors Mailman list: 
http://www.mail-archive.com/[email protected]/

To search via a non-Google archive, visit here: 
http://www.mail-archive.com/[email protected]/

To unsubscribe from this group, send email to
[email protected]

Reply via email to