Object

Object object

Despite of its name Object is a class that contains methods of objects in tiscript. Last line here will be evaluated to true:

var obj = { one:1, two:2 }; // creating object from literal
if( obj instanceof Object )
      stdout.printf( "I am an instance of Object" ); // will output this

Properties

className
readonly, string. Name of the class if object was created as instance of user defined class.
length
readonly, integer. Returns total number of members this instance contains.

Methods

this
( )

constructor, creates instance of Object class – object per se.

toString
toLocaleString
( ) : string

Returns string "[object Object]".

valueOf
( ) : value

Returns object itself.

clone
( [deep:true] ) : object

Makes copy of the object and returns it. If deep === true then it does recursive, deep cloning.

extend
( [deep:true], object1, object2, …  ) : this

Extends the object by merging its properties from properties of object1, object2, etc.

exists
( tag: value, [deep = false] ) : true | false

Checks property by its tag for existence. If deep == true then does deep lookup – in objects itself and its chain of classes.

remove
( tag: value ) : void

Removes property of the object by its tag (a.k.a. name).

call
( func: function, [p1:value, p2:value, … pN:value [, argv: array] ] ) : value

Calls the func with context of this equal to the object. Parameters if given passed to the function. If argv is provided then its memebers will be added to the list of parameters of the call.

show
( [out: Stream] ) : void

Reports class name and list of property name/values of the object. Intended to use for debugging purposes.

eval
( what: string | Stream [, namespace: object] ): value

Evaluates (interprets) what with context of this equal to the object. If namespace object is given then it is used as global namespace for evaluated code.

propertyAt
( tag: value ) : value

Does lookup in the object for member/property by its tag. This is a direct equivalent of obj.tag construction.

seal
( [strict:true|false] ) : object

Locks structure of the object – after the call any attempt to add or remove object’s property will throw an error. Values of existing properties can be changed though. Returns the object iself. If strict parameter is provided and it is exactly true then any attempt to get unknown property will throw an error.

isSealed
( [strict:true|false] ) : true | false | undefined

Returns true if the object is sealed. If strict parameter is provided and is exactly true then the method returns true only if seal(true) was called for it.

freeze
( [strict:true|false] ) : object

Locks the object – makes it immutable – any attempt to add, remove and modify value of any object’s property will throw an error. Returns the object itself. If there is a strict parameter and it is exactly true then any attempt to get unknown property will throw an error.

isFrozen
( [strict:true|false] ) : true | false | undefined

Returns true if the object is frozen. If strict parameter is provided and is exactly true then the method returns true only if freeze(true) was called for it.

addObserver
( observer:function ) : undefined

Attaches observer to the object – function that is called when the object changes. The observer here is a function that has following signature:

function observer(changeDefinition) {} where changeDefinition is tuple having following fields:

  • [0] – symbol, one of #add – property added, #update – property changed or #delete – property deleted;
  • [1] – object, the object that property was changed;
  • [2] – symbol or string, property name;
  • [3] – any, new value;
  • [4] – any, old value.
removeObserver
( observer:function | functionName:symbol ) : undefined

Detaches given observer function from the object by function reference or by its name.  

referenceOf
( namespace:object, path:string ) : (collection:object, key:symbol|string)
When given dot separated path like "one.two.three" the function returns obj/key pair – object in which "three" key is defined and that key.