1. #1
    Sencha Premium Member
    Join Date
    Nov 2012
    Posts
    11
    Vote Rating
    0
    cdamon is on a distinguished road

      0  

    Default Unanswered: Ext.create, constructors, and config

    Unanswered: Ext.create, constructors, and config


    Apologies if this has come up before. I'm fairly new to ST, but I feel I'm beginning to get it. The concept of configurations that automatically generate getters and setters (plus the apply and update functions) is useful and important.

    That's why I'm a bit surprised that the following doesn't work:

    Ext.define('MyApp.MyClass', {
    config: {
    foo: null,
    bar: null
    }
    });
    Ext.create('MyApp.MyClass', { foo: 'a', bar: 'b' });

    I would expect the object to be initialized with those values for 'foo' and 'bar'. Following the code, I see that it just calls the 'new' operator, passing the appropriate number of arguments.

    My guess is that config isn't handled because you can't be sure it's a config - it's just a single argument that happens to be an object. If that's the case, maybe passing a single argument that happens to be an object with only a single property of 'config' could trigger it.

    As it is, I end up writing trivial constructors like this:

    constructor: function(foo, bar) {
    this.setFoo(foo);
    this.setBar(bar);
    }

    Is there something I'm missing?

  2. #2
    Sencha User
    Join Date
    Mar 2007
    Posts
    413
    Answers
    5
    Vote Rating
    18
    jweber will become famous soon enough

      0  

    Default


    You need to call initConfig:

    Code:
    constructor: function(config) {
    	this.initConfig(config);
    }

  3. #3
    Sencha Premium Member
    Join Date
    Nov 2012
    Posts
    11
    Vote Rating
    0
    cdamon is on a distinguished road

      0  

    Default


    Ah, missed that somehow. Thanks!

Thread Participants: 1

Tags for this Thread