ASP.NET AJAX Function.createDelegate vs Function.createCallback?

I am reading a manning book - asp.net ajax in action. pages 54-58 describe client delegates and callbacks.

:

with a client delegate, you can change the variable in the event handler itself to reflect another object. (so this will not be the DOM object that raised the event for DOM events) this

with a callback you can pass to the event handler, which will be available in the event handler as the second argument / parameter . context object

and you can "pass" the object to the event handler (whether thisor not context object), which will not be available to the event handler (in its volume).

What is the difference between these client delegates and callbacks?

I think that:

only the object you want to use in the event handler is available in different ways :

  • customer delegate: this
  • callback: second argument

... and it is possible that only the callback has DomEvent (the first option) , but does not delegate the client ?! ??

It is right? It's all?

Perhaps you can explain the difference between client delegates and callbacks.

+3
source share
1 answer

I'm not sure about this, but I think the callback is what happens when the page is sent to the server.

, , JavaScript.

Function.CreateDelegate() .

, JavaScript. "this", , , - , .

, JavaScript, - . "this" JavaScript, Object "this", , : .

, JavaScript apply. , JavaScript attachEvent/attachEventListener ( $addHandler() Ajax.NET Framework), apply() attachEvent/attachEventListener. , "this" JavaScript , .

Function.CreateDelegate() , apply .

:

Function.createDelegate = function Function$createDelegate(instance, method) {
    /// <summary locid="M:J#Function.createDelegate" />
    /// <param name="instance" mayBeNull="true"></param>
    /// <param name="method" type="Function"></param>
    /// <returns type="Function"></returns>
    var e = Function._validateParams(arguments, [
    {name: "instance", mayBeNull: true},
    {name: "method", type: Function}
    ]);
    if (e) throw e;
    return function() {
      return method.apply(instance, arguments);
    }
} 

, apply(). , , . , createDelegate .

, , , createDelegate() - , JavaScript , .

, - , , . __doPostback . 2 ... , / , / . .

-Frinny

+3

Source: https://habr.com/ru/post/1708630/


All Articles