propertyDefaults
Specify default behaviors for properties on a ObservableArray.
static propertyDefaults = PROPDEFINITION
Specify default values using a [can-observable-object/object.types.propDefinition] object.
import { ObservableArray, ObservableObject, type } from "can/everything";
class Player extends ObservableObject {
}
class Players extends ObservableArray {
static propertyDefaults = {
type: type.convert(Number)
};
static items = Player;
}
const team = new Players();
team.rank = "5";
console.log(team.rank); // -> 5
The above specifies a RouteData type whose properties default to a strictly typed String
and are non-enumerable.
static propertyDefaults = PROPERTY
propertyDefaults can be specified using any of the methods specified by the property type.
import { ObservableArray } from "can/everything";
class People extends ObservableArray {
static propertyDefaults = String;
}
The above specifies all properties to default to being a strictly defined String
. See Property for other possible values.
This does not set the type for items within the array. Use items for that.