When the constructor encounters the YUI3 encapsulation Mechanism

Source: Internet
Author: User

Copy to ClipboardReference: [www.bkjia.com]/*
* Create confirmation dialog box
* @ Constructor ConfirmBox
*/

Var ConfirmBox, confirmOff, confirmDel;

ConfirmBox = function (msg, url ){

This. msg = msg;
This. url = url;

};

ConfirmBox. prototype. fire = function (e ){

Var message = confirm (this. msg );

If (message ){

Window. location. href = this. url;

}
};

/*
* Are you sure you want to dismount this project?
* @ Instance confirmOff
*/
ConfirmOff = new ConfirmBox ('Are you sure you want to dismount this project? ', Config. offUrl );

If (Y. all ('. sale-off ')){
Y. on ('click', confirmOff. fire, '. sale-off', confirmOff );
}

Due to the encapsulation mechanism of YUI3, the default context environment for event registration through Y. on is Y object. In a JavaScript constructor, when the prototype method calls this, it points to the instantiated object itself. If the context is not reset to the instance itself, it goes down. If it is not reset, the console. log this. msg attribute is the following:

Related Article

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.