This question pertains to Javascript in classic ASP. It has nothing to do with Javascript running in browsers.
A typical construct for a JS module that is designed to be re-usable is like this:
(function(globalScope) {
... declarations here...
}(this));
This allows the code to be syntactically encapsulated, to allow checks by the run-time parser/compiler. It also provides scope management, so that vars and functions declared within the curlies will not be visible externally.
Another typical construct is to "export" an object or function belonging to the inner scope, to the outer scope, via assignment, like this:
(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.
When using this sort of construct in classic ASP (attention: server-side javascript!!) the JS engine throws up. I get a 500 error.
Why?
Can I use the scoping construct and "export" things to the global scope, in classic ASP?
In a browser runtime, "this" evaluates to "window". In a server-side classic ASP runtime, what is the value of the global "this"? Is it possible to assign new properties to that "this" ?