New nsIScriptable interface: Difference between revisions

Line 163: Line 163:
==== Contrived dialog widget ====
==== Contrived dialog widget ====


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.
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 namespace = s.GetLanguageGlobal(lang_id, window)
     var global = s.getLanguageGlobal(lang_id, window)
     var func = namespace.ondialogaccept
     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::Invoke with a
|func(event)| would then automatically call nsIScriptable::invoke with a
DISPID of DISPID_DEFAULT.
DISPID of DISPID_DEFAULT.
      
      
or the sake of completeness, the above could also obviously be written as:
For the sake of completeness, the above could also obviously be written as:


     var namespace = s.GetLanguageGlobal(lang_id, window)
     var global = s.getLanguageGlobal(lang_id, window)
     var namespace.ondialogaccept(event)
     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 Invoke for 'ondialogaccept' may be done as a method call, assuming
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.
Confirmed users, Bureaucrats and Sysops emeriti
419

edits