[ 3 posts ]

John Mizliso

  • Username: abxccd
  • Joined: Sun Jan 22, 2012 11:20 pm
  • Posts: 48
  • Offline
  • Profile
Tags:

Constructors when using Y.Base.create

Post Posted: Tue Feb 28, 2012 1:45 am
+0-
Is it possible to have constructors when using Y.Base.create?

This is a component I am writing:

Code:
YUI.add('mycomponent', function (Y) {
   Y.namespace('myapp');
   
   var mycomponent;
   
   mycomponent = Y.Base.create('mycomponent', Y.Base, [], {

    mycomponent: function(config){ //This doesn't seem to be used as the constructor
      Y.log(config);
    },
      
       add: function () {
          Y.log('hi');
       },
      
      
      

   }, {});

   Y.namespace('myapp').mycomponent = mycomponent;
   
}, '1.0.0', {
    requires: ['node'
              ,'base']
});


I then use it like this:
Code:
var comp= new Y.myapp.mycomponent(Y.one('#test')); //Does not work


How can I set up my component so that it has a constructor that can be passed values during instantiation?

Satyam

YUI Contributor

  • Username: Satyam
  • Joined: Tue Dec 09, 2008 12:34 am
  • Posts: 2016
  • Location: Sitges, Spain
  • GitHub: Satyam
  • Gists: Satyam
  • IRC: DevaSatyam
  • YUI Developer
  • Offline
  • Profile

Re: Constructors when using Y.Base.create

Post Posted: Tue Feb 28, 2012 2:53 am
+0-
You use the initializer method to do what a constructor would normally do. It receives the same arguments the constructor would receive and it doesn't need to chain to the superclass constructor since Base takes care of that.

John Mizliso

  • Username: abxccd
  • Joined: Sun Jan 22, 2012 11:20 pm
  • Posts: 48
  • Offline
  • Profile

Re: Constructors when using Y.Base.create

Post Posted: Tue Feb 28, 2012 3:00 am
+0-
Thank you :)
  [ 3 posts ]
Display posts from previous:  Sort by  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum