DoneJS StealJS jQuery ++ FuncUnit DocumentJS
3.0.0
2.3.27

 

  • Github
  • Twitter
  • Chat
  • Forum
  • Guides
  • Core
  • Ecosystem
  • Infrastructure
    • can-construct
      • prototype
        • constructor
        • init
        • setup
      • static
        • constructorExtends
        • extend
        • newInstance
        • setup
        • shortName
    • can-control
    • 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-construct
  • /
  • constructorExtends
  • / On this page
    • constructorExtends

      property

      Toggles the behavior of a constructor function called without the new keyword to extend the constructor function or create a new instance.

      var animal = Animal();
      // vs
      var animal = new Animal();
      
      • source

      Boolean

      If constructorExtends is:

      • true - the constructor extends
      • false - a new instance of the constructor is created

      This property defaults to false.

      Example of constructExtends as true:

      var Animal = Construct.extend({
        constructorExtends: true // the constructor extends
      },{
        sayHi: function() {
          console.log("hai!");
        }
      });
      
      var Pony = Animal({
        gallop: function () {
           console.log("Galloping!!");
        }
      }); // Pony is now a constructor function extended from Animal
      
      var frank = new Animal(); // frank is a new instance of Animal
      
      var gertrude = new Pony(); // gertrude is a new instance of Pony
      gertrude.sayHi(); // "hai!" - sayHi is "inherited" from Animal
      gertrude.gallop(); // "Galloping!!" - gallop is unique to instances of Pony
      

      The default behavior is shown in the example below:

      var Animal = Construct.extend({
        constructorExtends: false // the constructor does NOT extend
      },{
        sayHi: function() {
          console.log("hai!");
        }
      });
      
      var pony = Animal(); // pony is a new instance of Animal
      var frank = new Animal(); // frank is a new instance of Animal
      
      pony.sayHi() // "hai!"
      frank.sayHi() // "hai!"
      

      By default to extend a constructor, you must use extend.

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