Global ScriptObject prototype

  • Updated

As noted in the section “ScriptObject data type”, irScript supports a notion of inheritance called prototyping. This allows an instance of ScriptObject to (optionally) declare during creation another instance as its logical parent (or “prototype”). All methods and properties of the prototype are available to the “child” ScriptObject.

ScriptObject instances that don’t explicitly declare a prototype during creation will implicitly be assigned the global ScriptObject prototype. Ultimately, this places the global ScriptObject as the (eventual) ancestor of all ScriptObject instances.

By default, this global prototype instance has no special properties or methods beyond the defaults for any other instance (the one exception being the global prototype’s Prototype property, which always returns null).

It’s sometimes useful to assign properties or methods to this global prototype instance, however; this allows all ScriptObject instances to inherit these members themselves. The root instance is always accessible via the well-known identifier ‘__RootPrototype’:

__RootPrototype.ComputeValue = function ( arg1, arg2 ) { return arg1 * arg2 * 34.3; };
var x = {};
var y = {};
var result1 = x.ComputeValue( 33, 1.2223 );
var result2 = y.ComputeValue( 9901.1, 0.003 );

Note that attempting to re-assign the value of the root prototype instance results in an error.

Was this article helpful?

0 out of 0 found this helpful

Comments

0 comments

Please sign in to leave a comment.