-
Notifications
You must be signed in to change notification settings - Fork 0
API: Script Keys and Objects
#ScriptObjectKeys ScriptObjectKeys and ScriptObjectKey are the underpinnings of the type system used by all scriptable objects in libscriptobject. A key is made up from a field name and type (string, int, null, etc.), objects have one or more keys which ultimately describe the type of the object. Consider:
var x = { pi: 3.14159, theAnswer: 42 };
var y = { theAnswer: 42, pi: 3.14159 };
These two objects have fields x and y which both have the same types. Inside libscriptobject the object instances x and y both have keys which are used to describe the object, if we were to compare the keys (name and field type) then we could say the objects are the same 'type' since they are equivalent at the key level.
Being able to track type equivalence for scriptable objects is a useful optimization; we can store a single instance of the keys describing the type and refer to that instance from all type-equivalent objects.
This technique saves both memory and CPU time but has a number of limitations. What happens when fields change type or when fields are removed or added? Generally objects in libscriptobject are immutable.