[JavaScript] an issue to be aware of when using block-level scope to declare an object
Source: Internet
Author: User
[Javascript] (function () {this. title & quot; prompt message & quot; this. showfunction () {}; this. closefunction () {}; messagethis ;}). (); the role of the above Code is to declare a globally unique object message. Here it declares... [javascript]
(Function (){
This. title = "prompt message ";
This. show = function (){
};
This. close = function (){
};
Message = this;
}).();
The function of the above Code is to declare a globally unique object message. Here it declares close (), because the block-level scope is passed in by default in the window, so after the above code is executed, window. the close () method will be ineffective (but it can work normally in IE9 browser and IE9 document mode, but not in Chrome or other versions of IE ), the solution to this problem is: www.2cto.com
[Javascript]
(Function (){
This. title = "prompt message ";
This. show = function (){
};
This. close = function (){
};
Message = this;
}). Call ({}); // upload an object to change the default window scope.
Author: bclz_vs
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.