extend
Define a custom list type.
DefineList.extend([name,] [static,] prototype)
Extends DefineList, or constructor functions derived from DefineList, to create a new constructor function.
var DefineList = require("can-define/list/list");
var 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;
})
}
});
var todos = new TodoList([
{name: "dishes", complete: false},
{name: "lawn", complete: false}
]);
todos.availableCount = 100;
todos.completeAll();
todos.completeCount //-> 2
Parameters
- name
{String}
:Provides an optional name for this type that will show up nicely in debuggers.
- static
{Object}
:Static properties that are set directly on the constructor function.
- prototype
{Object<String,function|PropDefinition>}
:A definition of the properties or methods on this type.