From RTSC-Pedia
[printable version] [offline version] | offline version generated on 04-Aug-2010 21:08 UTC |
XDCscript - Instance-Object.Function-Name
Instance method
Contents |
Synopsis
| «inst».«methodName» |
where «inst» is an instance object and «methodName» is the name of a method whose type signature is specified in a function-declaration.
Description
Methods of an instance object are module-specific properties declared in the module's .xdc specification file. Only methods declared to be metaonly (directly or indirectly) can invoked from scripts; all other method name simply represent the type signature of a function that can be invoked on the target.
Meta-only methods are functions that can be directly invoked from scripts. For example, instance method getName of the module pkg.Mod can be run from a script as shown below.
| var Mod = xdc.module("pkg.Mod"); /* get the module */ var inst = Mod.create(); /* create an instance */ print(inst.getName()); /* run an instance method and print result */ |
Meta-only methods have a distinguished function property named $apply that allows them to be invoked with a user specified this pointer. This can be useful when a method needs to invoke the meta-only method associated with an inherited interface. Suppose for example that the pkg1.Mod module inherits from the interface pkg2.IMod. If pkg2.IMod declares and implements a method, say getName, the module pkg1.Mod can both override the implementation provided by pkg2.IMod and invoke the overridden method.
Mod.xs | |
| function getName() { var sup = this.$super.getName.$apply(this, []); /* get inherited name */ return (sup+ ":Mod"); /* return "super_name:my_name" */ } |
The $apply() function has the same signature and semantics as the JavaScript apply() method of Functions.
See also
XDCscript - Instance-Object | Object containing per-instance-features of a module |
XDCscript - Instance-Object.$super | Instance of the inherited-interface |
[printable version] [offline version] | offline version generated on 04-Aug-2010 21:08 UTC |