DoneJS StealJS jQuery ++ FuncUnit DocumentJS
3.0.0
2.3.27

 

  • Github
  • Twitter
  • Chat
  • Forum
  • Guides
  • Core
    • can-component
    • can-compute
    • can-connect
    • can-define
    • can-define/list/list
      • events
        • add
        • length
        • propertyName
        • remove
      • prototype
        • concat
        • filter
        • forEach
        • get
        • indexOf
        • join
        • map
        • on
        • pop
        • push
        • replace
        • reverse
        • serialize
        • set
        • shift
        • slice
        • sort
        • splice
        • unshift
        • *
        • #
      • static
        • extend
    • can-define/map/map
    • can-route
    • can-route-pushstate
    • can-set
    • can-stache
    • can-stache/helpers/route
    • can-stache-bindings
  • Ecosystem
  • Infrastructure
  • Legacy
  • Bitovi
    • Bitovi.com
    • Blog
    • Consulting
    • Training
    • Open Source
  • Chat
  • Forum
  • Star
  • Follow @canjs
  • CanJS
  • /
  • Core
  • /
  • can-define/list/list
  • /
  • extend
  • / On this page
    • extend

      function

      Define a custom list type.

      • source

      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

      1. name {String}:

        Provides an optional name for this type that will show up nicely in debuggers.

      2. static {Object}:

        Static properties that are set directly on the constructor function.

      3. prototype {Object<String,function|PropDefinition>}:

        A definition of the properties or methods on this type.

      Returns

      {can-define/list/list}:

      A DefineList constructor function.

      CanJS is part of DoneJS. Created and maintained by the core DoneJS team and Bitovi. Currently 3.0.0.