This project is read-only.

Model Entities and JavaScript Types

All model types have a corresponding JavaScript "class" of the same name. In other words, the ExoWeb model generates code on the client based on its meta model. This makes application code more seamless. Also, the meta model is cleaner in that property types can be of any JavaScript type, which includes JavaScript intrinsic types or model type classes.

Object Identity

All entities have a id property, , that uniquely identifies the instance. For consistency and simplicity all ids are strings. If the server-side model uses types other than strings that is fine because the ExoWeb service translates those types to and from strings on the client to maintain that abstraction.

Identity is shared across a family of classes. For example, consider the situation where there is a base class, Animal with subclasses Dog and Cat then Animal.meta.get(aDogId) === Dog.meta.get(aDogId) is true.

For objects that are not yet persisted, ExoWeb will generate a client-only ID that will be used until the object has been persisted. These ids are typically in the format: "+c000" where 000 is a unique integer. After the object is persisted its property will be updated. However, the object can still be referenced using its old ID for the lifetime of the page to help simplify application code.

Object Construction and Lifecycle

Objects are always constructed using the standard Javascript constructor for the entity type. There are several ways the the constructor can be called:

Constructors Description
new SomeEntity() creates a new employee object with its default state
new SomeEntity({prop1: val1, prop2: val2, propN: valN }) creates a new employee object with its default state and then sets its properties based on the argument
new SomeEntity(id) creates a employee object that will be bound to the persisted state identified by id . This object may not yet be loaded. See Server communication for information on loading.


Single inheritance among entity classes is fully supported and all model classes derive from ExoWeb.Model.Entity . Inheritance is exposed naturally though using standard javascript prototype-based inheritance. This means that the instanceof operator works as expected.

Extending Types with $extend()

Using the $extend function, it is possible to augment the built-in behavior of a type, which can be set up before the type exists.

function $extend(typeInfo, callback)

typeInfo The string type name, or an array of string type names.
callback A JavaScript function to be executed when the type(s) are available. Note: If a single type name is used the argument to the callback method will be the JavaScript constructor function. If an array of names is used then the argument(s) will be the constructor functions, in the order that they were listed.

	$extend("Person", function(type) {
		// NOTE:  The "type" variable refers to the "Person" JavaScript constructor function.  To get the model type, use the "meta" attribute.
		type.meta.addProperty({ /* property information */);
	$extend(["Person", "Place"], function(person, place) {
		person.meta.addProperty({ /* property information */);
		place.meta.addProperty({ /* property information */);

Property Paths

Property paths must, with one exception, always start with a "this" reference for instance properties or the containing class name for static properties. The exception to this rule is when a property looked up via"path").


Property paths can include type directives. This directives are used to determine which class to look for the property on which is needed in some cases where inheritance is used.


The will cause the Sections to be treated as if its of type IepServices. In this case, this property is a list of mixed types so the type directive also will act as a filter and ignore events from objects that are not of that type.

Last edited Apr 16, 2010 at 10:33 PM by matthooper, version 4


No comments yet.