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
  • /
  • options
  • / On this page
    • options

      property

      Options used to configure a control.

      • source

      Object

      Options Object

      The this.options property is an Object that contains configuration data passed to a control when it is created (new Control(element, options)).

      In the following example, an options object with a message is passed to a Greeting control. The Greeting control changes the text of its element to the options' message value.

      var Greeting = Control.extend({
          init: function(){
              this.element.text( this.options.message )
          }
      });
      
      new Greeting("#greeting",{message: "I understand this.options"});
      

      The options argument passed when creating the control is merged with defaults in setup.

      In the following example, if no message property is provided, the defaults' message property is used.

      var Greeting = Control.extend({
          defaults: {
              message: "Defaults merged into this.options"
          }
      },{
          init: function(){
              this.element.text( this.options.message )
          }
      });
      
      new Greeting("#greeting");
      

      Options Observable

      An observable CanMap or DefineMap can also be passed instead of an options object.

      In the following example, the defaults' message property is set on the DefineMap options observable, which is then set directly as this.options:

          var GreetingControl = Control.extend({
              defaults: {
                  message: 'Hello'
              }
          }, {
              init: function(){
                  this.element.text( this.options.message + ' ' + this.options.name )
              }
          });
      
          var GreetingMap = DefineMap.extend({
              message: 'string',
              name: 'string'
          });
      
          var data = new GreetingMap();
          data.name = 'Kevin';
      
          new GreetingControl('#greeting', data);
      

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