can-define
Version:
Create observable objects with JS dot operator compatibility
53 lines (39 loc) • 1.3 kB
Markdown
can-define/list/list.extend extend
can-define/list/list.static
Define a custom list type.
`DefineList.extend([name,] [static,] prototype)`
Extends DefineList, or constructor functions derived from DefineList,
to create a new constructor function.
```js
import DefineList from "can-define/list/list";
const TodoList = DefineList.extend(
"TodoList",
{
"#": { type: { complete: "boolean", name: "string" } },
availableCount: "number",
completedCount: {
get: function() {
return this.filter( { complete: true } ).length;
}
},
completeAll: function() {
this.forEach( function( todo ) {
todo.complete = true;
} );
}
} );
const todos = new TodoList( [
{ name: "dishes", complete: false },
{ name: "lawn", complete: false }
] );
todos.availableCount = 100;
todos.completeAll();
todos.completeCount; //-> 2
```
{String} [name] Provides an optional name for this type that will
show up nicely in debuggers.
{Object} [static] Static properties that are set directly on the
constructor function.
{Object<String,Function|can-define.types.propDefinition>} prototype A definition of the properties or methods on this type.
{can-define/list/list} A DefineList constructor function.