Confirmed users, Bureaucrats and Sysops emeriti
419
edits
Line 163: | Line 163: | ||
==== Contrived dialog widget ==== | ==== Contrived dialog widget ==== | ||
Below is a contrived example that demonstrates | Below is a contrived example that demonstrates getLanguageGlobal. Let's assume the design of the dialog widget was such that it simply assumed a global function called "ondialogaccept" in the window namespace. | ||
For example, let's assume a dialog widget insisted you structure your dialog like: | For example, let's assume a dialog widget insisted you structure your dialog like: | ||
Line 177: | Line 177: | ||
Assuming nsIScriptable, this could be implemented in a language agnostic fashion as follows: | Assuming nsIScriptable, this could be implemented in a language agnostic fashion as follows: | ||
var | var global = s.getLanguageGlobal(lang_id, window) | ||
var func = | var func = global.ondialogaccept | ||
var ret = func(event) | var ret = func(event) | ||
Line 186: | Line 186: | ||
would be looked up as a simple property reference, and as a function | would be looked up as a simple property reference, and as a function | ||
object would be found, |func| would itself be an nsIScriptable. | object would be found, |func| would itself be an nsIScriptable. | ||
|func(event)| would then automatically call nsIScriptable:: | |func(event)| would then automatically call nsIScriptable::invoke with a | ||
DISPID of DISPID_DEFAULT. | DISPID of DISPID_DEFAULT. | ||
For the sake of completeness, the above could also obviously be written as: | |||
var | var global = s.getLanguageGlobal(lang_id, window) | ||
var | var ret = global.ondialogaccept(event) | ||
In this case the use of nsIScriptable may be slightly different - the | In this case the use of nsIScriptable may be slightly different -- the | ||
initial | initial invoke for 'ondialogaccept' may be done as a method call, assuming | ||
the language is capable of detecting that situation. | the language is capable of detecting that situation. |