<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/">
  <channel>
    <title>ASP.NET AJAX Client Library: Combining createDelegate and createCallback</title>
    <link>http://blogs.lotterypost.com/speednet/2008/5/aspnet-ajax-client-library-combining-create.htm</link>
    <atom:link href="http://www.lotterypost.com/rss/blogcomments/22654" rel="self" type="application/rss+xml" />
    <description>Speednet's Blog: ASP.NET AJAX Client Library: Combining createDelegate and createCallback</description>
    <dc:language>en-us</dc:language>
    <generator>Lottery Post RSS Generator</generator>
    <item>
      <title>Comment #1</title>
      <link>http://blogs.lotterypost.com/speednet/2008/5/aspnet-ajax-client-library-combining-create.htm</link>
      <guid isPermaLink="true">http://blogs.lotterypost.com/speednet/2008/5/aspnet-ajax-client-library-combining-create.htm</guid>
      <pubDate>Sun, 12 Oct 2008 21:05:35 GMT</pubDate>
      <dc:creator>aboudreau</dc:creator>
      <description><![CDATA[Hey speednet, fantastic article this is exactly what i'm looking for.  although i've got a few questions for you.  1. Should i have any concern about memory leaks with this, i'm just getting ready to look into method.apply, and method.call since i'm not to familar with these lower level methods.  So, i'm nervous that i'm not going to dispose the closure correctly.  Second, i'm adding this "delegate/callback" as an event handler and i'm not getting the event argument into the delegate/callback.  ... [&nbsp;<a href="http://blogs.lotterypost.com/speednet/2008/5/aspnet-ajax-client-library-combining-create.htm">More</a>&nbsp;]]]></description>
      <category>aboudreau</category>
    </item>
    <item>
      <title>Original Blog Entry: ASP.NET AJAX Client Library: Combining createDelegate and createCallback</title>
      <link>http://blogs.lotterypost.com/speednet/2008/5/aspnet-ajax-client-library-combining-create.htm</link>
      <guid isPermaLink="true">http://blogs.lotterypost.com/speednet/2008/5/aspnet-ajax-client-library-combining-create.htm</guid>
      <pubDate>Wed, 28 May 2008 19:27:48 GMT</pubDate>
      <dc:creator>Speednet</dc:creator>
      <description><![CDATA[<p>When working with the ASP.NET AJAX client library, I find that I occasionally need to use both <span style="font-family: Courier New,Courier,monospace;">Function.createDelegate()</span> and <span style="font-family: Courier New,Courier,monospace;">Function.createCallback()</span> simultaneously.</p><p>Each time you use one or the other of these methods, the library places a &quot;call wrapper&quot; around&nbsp;your function.&nbsp; Then, when the new delegate (or callback) is called, there are actually two calls being made: the first to the wrapper, and the second when the wrapper calls&nbsp;your function.</p><p>By combining the use of both methods, you're now placing <strong>two</strong> call wrappers around your function, which is&nbsp;fairly inefficient, not to mention that it's not exactly elegant or readable.</p><p>Why would you want to combine the two methods?</p><p>You'd want to combine them when you want to ensure that&nbsp;<span style="font-family: Courier New,Courier,monospace;">this</span> refers to a specific object, and you also want to pass specific arguments (&quot;context&quot;) to the function.</p><p>For example, let's start with&nbsp;two&nbsp;objects,&nbsp;each containing an array of messages (strings).&nbsp; &nbsp;We also have a&nbsp;function that expects that <span style="font-family: Courier New,Courier,monospace;">this</span> will refer to&nbsp;one of the objects, and it will expect to receive the index of the message to display as an argument.</p><p>(This is a very contrived example, but it shows the requirement and solution in simple terms.&nbsp; Real-world situations that require the use of both <span style="font-family: Courier New,Courier,monospace;">createDelegate</span> and <span style="font-family: Courier New,Courier,monospace;">createCallback</span> are more complex.)</p><p style="background-color:#f0f0f0; padding:6px; border:1px dashed #999;"><span style="font-family: Courier New,Courier,monospace;">var myObject1 = {<br /> &nbsp; &nbsp; messages: [&quot;Red&quot;, &quot;Blue&quot;, &quot;Black&quot;]<br /> };<br /><br /> var myObject2 = {<br /> &nbsp; &nbsp; messages: [&quot;Audi&quot;, &quot;Chevy&quot;, &quot;Mitsubishi&quot;]<br /> };<br /><br /> function showAlert(index) {<br /> &nbsp; &nbsp; alert(this.messages[index]);<br /> };</span></p><p>Now, I'll create two delegates/callbacks: one will call....</p><p>[ <a href="http://blogs.lotterypost.com/speednet/2008/5/aspnet-ajax-client-library-combining-create.htm">More</a> ]</p>]]></description>
      <category>* Original Blog Entry</category>
      <wfw:comment>http://www.lotterypost.com/blogentry/22654</wfw:comment>
    </item>
  </channel>
</rss>
