Function. createdelegate usage

Source: Internet
Author: User

Function. createdelegate is the most common method for function encapsulation. Function signature:

Function. createdelegate (instance, method)

This method returns a callback function.

For example:
Fireafter: function (seconds)
{
SetTimeout (function. createdelegate (this, this. _ timeoutcallback), seconds * 1000 );
},

If a function is directly handed over to some HTML controls as the callback function, the object referenced by this is the control when an event occurs, rather than the custom object. For example, a function is handed over to window. after setTimeout, This is the window. Function. createdelegate solves this problem. It is recommended that you use this method to respond to the callback of the HTML control. It ensures that when the method parameter references the method to be called, this must reference the instance parameter object.

Transferred from: http://aloneplayer.spaces.live.com/blog/cns! C3cb6d654135f83d! 371. Entry

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.