Skip to main content
Hitachi Vantara Lumada and Pentaho Documentation

Instance

pentaho.type. Instance

The root, abstract class of things that can be represented by the Pentaho Type API.

Types are constituted by two classes (or constructors): the instance class and the type class.

The former creates the actual instances of the type. The latter creates a single object (a singleton) that represents the type, which is shared by all instances of the type, and essentially, holds its metadata.

The type class of the Instance type is pentaho.type.Type.

When creating a subclass Foo of Instance, the corresponding type class is implicitly generated (a subclass of Type), and its singleton object is placed in the static property Foo.type.

Instances of the type Foo can also conveniently access the type's singleton object through the instance property this.$type.

The instance and type classes of a type are closely bound and must naturally reference each other. The type singleton object references back the prototype of the instance class, in a property named instance.

AMD Module

require(["pentaho/type/instance"], function(Instance) { /* code goes here */ });

See also: pentaho.type.spec.UInstanceModule , pentaho.type.spec.UTypeModule , pentaho.type.spec.IInstance , pentaho.type.spec.IInstanceProto , pentaho.type.spec.ITypeProto

Constructor

Name Description
new Instance()
Abstract

Creates an instance of this type.

Members

Name Description
type :  pentaho.type.Type
Static

Gets the type of this instance constructor.

$type :  pentaho.type.Type

Gets the type of this instance.

Methods

Name Description
extend(name, instSpec, classSpec, keyArgs) : Class.<<code>pentaho.type.Value>
Static

Creates a subtype of this one.

toJSON() : UJsonValue

Creates a top-level JSON specification that describes this instance.

toSpec(keyArgs) : any

Creates a top-level specification that describes this instance.

toSpecInContext(keyArgs) : any
Abstract

Creates a specification that describes this instance.

Constructor Details

new Instance()
Abstract

Creates an instance of this type.

Source: javascript/web/pentaho/type/instance.js, line 33

See also: pentaho.type.spec.UInstanceModule , pentaho.type.spec.UTypeModule , pentaho.type.spec.IInstance , pentaho.type.spec.IInstanceProto , pentaho.type.spec.ITypeProto

Example

Create a new class Derived containing an attribute greeting and a method doSomething.

require(["pentaho/type/Context"], function(Context) {

 Context.createAsync(function(context) {

 var Instance = context.get("instance");

 var Derived = Instance.extend({
 constructor: function(label) {
 this.label = label;
 },
 $type: { // type specification
 greeting: "Hello, ",
 veryLongString: "..."
 },
 saySomething: function() {
 console.log(this.$type.greeting + this.label + "!");
 }
 });

 var a = new Derived("Alice");
 a.saySomething(); // "Hello, Alice!"

 var b = new Derived("Bob");
 b.saySomething(); // "Hello, Bob!"

 // All instances share the same _type_:
 b.$type.greeting === a.$type.greeting // true
 });
});

Members Details

type:  pentaho.type.Type
Static

Gets the type of this instance constructor.

Source: javascript/web/pentaho/type/instance.js, line 223

$type:  pentaho.type.Type

Gets the type of this instance.

Source: javascript/web/pentaho/type/instance.js, line 128

See also: pentaho.type.Instance.type , pentaho.type.Type#instance

Methods Details

extend(name, instSpec, classSpec, keyArgs) : Class.<<code>pentaho.type.Value>
Static

Creates a subtype of this one.

For more information on class extension, in general, see pentaho.lang.Base.extend.

Source: javascript/web/pentaho/type/instance.js, line 238

Parameters:
Name Default Value Summary
name : string
Optional

The name of the created class. The name of the created class is used for debugging purposes.

instSpec : pentaho.type.spec.IInstanceProto
Optional

The instance specification.

classSpec : Object
Optional

The static specification.

keyArgs : Object
Optional

The keyword arguments.

Returns:
Name Description
Class.<<code>pentaho.type.Value>

The new value subclass.

See also: pentaho.lang.Base.extend

toJSON() : UJsonValue

Creates a top-level JSON specification that describes this instance.

Attributes which do not have a JSON-compatible specification are omitted. Specifically, for inline types, attributes with a function value are not supported.

This method simply calls pentaho.type.Instance#toSpec with argument keyArgs.isJson as true and exists for seamless integration with JavaScript's JSON.stringify method.

Source: javascript/web/pentaho/type/instance.js, line 210

Returns:
Name Description
UJsonValue

A JSON-compatible specification.

See also: pentaho.type.Instance#toSpec

toSpec(keyArgs) : any

Creates a top-level specification that describes this instance.

If an ambient specification context currently exists, it is used to manage the serialization process. Otherwise, one is created and set as current. Then, the actual work is delegated to pentaho.type.Instance#toSpecInContext.

Source: javascript/web/pentaho/type/instance.js, line 172

Parameters:
Name Default Value Summary
keyArgs : Object
Optional

The keyword arguments' object. Passed to every instance and type serialized within this scope.

Please see the documentation of subclasses for information on additional, supported keyword arguments.

Parameters:
Name Default Value Summary
isJson : boolean
Optional
false

Generates a JSON-compatible specification. Attributes that do not have a JSON-compatible specification are omitted.

declaredType : pentaho.type.Type
Optional

The base type of this value's storage location. If the value does not have this exact type, its inline type property must be included in the specification. Otherwise, it can be omitted. When unspecified, the inline type property is only included if forceType is true.

forceType : boolean
Optional
false

In the specification, forces inclusion of the inline type property: _.

Returns:
Name Description
any

A specification of this instance.

toSpecInContext(keyArgs) : any
Abstract

Creates a specification that describes this instance.

Source: javascript/web/pentaho/type/instance.js, line 190

Parameters:
Name Default Value Summary
keyArgs : Object
Optional

The keyword arguments' object. Passed to every instance and type serialized within this scope.

Please see the documentation of subclasses for information on additional, supported keyword arguments.

Returns:
Name Description
any

A specification of this instance.

See also: pentaho.type.Instance#toSpec