DoneJS StealJS jQuery ++ FuncUnit DocumentJS
3.0.0
2.3.27

 

  • Github
  • Twitter
  • Chat
  • Forum
  • Guides
  • Core
  • Ecosystem
  • Infrastructure
    • can-construct
    • can-control
      • static
        • defaults
        • extend
        • processors
      • prototype
        • destroy
        • element
        • on
        • options
        • setup
    • can-event
    • can-event/async/async
    • can-event/batch/batch
    • can-observation
    • can-simple-map
    • can-util
    • can-view-callbacks
    • can-view-live
    • can-view-model
    • can-view-nodelist
    • can-view-parser
    • can-view-scope
    • can-view-target
  • Legacy
  • Bitovi
    • Bitovi.com
    • Blog
    • Consulting
    • Training
    • Open Source
  • Chat
  • Forum
  • Star
  • Follow @canjs
  • CanJS
  • /
  • Infrastructure
  • /
  • can-control
  • /
  • defaults
  • / On this page
    • defaults

      property

      Default values for the Control's options.

      • source

      Object

      Default options provided for when a new control is created without values set in options.

      defaults provides default values for a Control's options. Options passed into the constructor function will be shallowly merged into the values from defaults in setup, and the result will be stored in this.options.

      Message = Control.extend({
        defaults: {
          message: "Hello World"
        }
      }, {
        init: function(){
          this.element.text( this.options.message );
        }
      });
      
      new Message( "#el1" ); //writes "Hello World"
      new Message( "#el12", { message: "hi" } ); //writes hi
      

      Shared Properties

      New instances of a Control will create a shallow copy of the default options. Be aware as shallow copies keep a reference to object types, such as objects, maps and computes.

      var Sample = Control.extend({
        defaults: {
          computedProp: can.compute(),
          primitiveProp: 'sample'
        }
      }, {});
      
      var a = new Sample('div');
      var b = new Sample('li');
      
      //`computedProp` will be shared across instances of the `Sample` control.
      //a.options.computedProp === b.options.computedProp
      

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