Insert objects into global scope in classic ASP / Javascript

This question is about Javascript in classic ASP. This has nothing to do with JavaScript running in browsers.

A typical JS module design for reuse is as follows:

(function(globalScope) {
   ... declarations here...
}(this));

This allows you to syntactically encapsulate the code to allow parser / compiler checks at runtime. It also provides scope management so that the vars and functions declared inside the curlicues will not be visible from the outside.

Another typical construction is to β€œexport” an object or function belonging to the inner region to the outer region through an assignment, for example:

(function(globalScope) {
   var data = ['Alpha', 'Beta', 'Gamma'];

   function helper(a) { .... } 

   function search(d) { .... }

   // "export" a function so it is externally visible
   globalScope.searchData = search; 

}(this));

// typeof this.searchData == "function" 
// typeof this.data == "undefined"
// typeof this.helper == "undefined"
// typeof this.search == "undefined"

This is all pretty typical.

ASP (: javascript!!) JS . 500 .

?

"" , ASP?

"this" "". ASP- , "this"? "this"?

+5
1

, , - COM-. COM- IDispatchEx, . COM- MSHTML, Internet Explorer DHTML. , , ASP ​​ .

, , globalScope, , - :

(function() { 
   var data = ['Alpha', 'Beta', 'Gamma']; 

   function helper(a) { .... }  

   function search(d) { .... } 

   // "export" a function so it is externally visible 
   searchData = search;  

})();   // Please not also small syntatic correction of your original code.

, searchData . JScript .

searchData Active Script (.. VBScript , VBScript searchData). , this.searchData. , , , Script.

+2

All Articles