1. #1
    Sencha User
    Join Date
    Dec 2011
    Posts
    2
    Vote Rating
    0
    jeffm712 is on a distinguished road

      0  

    Default Ext4 - Function Constructors? Why?

    Ext4 - Function Constructors? Why?


    Hello to all the folks at Sencha. I read through your MVC architecture guide, and I'm incredibly impressed with what you've put together, and despite my criticism below, I have a great deal of respect for you guys.


    I wanted to talk about the frequent use of Function constructors in Ext4. I'm confused by the decision to do this. Function constructors are tantamount to eval, and is generally considered bad practice. And it doesn't seem that difficult to avoid them.


    For example, here's an edit I made:


    Original Ext code:
    Code:
            getInstantiator: function(length) {
                if (!this.instantiators[length]) {
                    var i = length,
                        args = [];
    
    
                    for (i = 0; i < length; i++) {
                        args.push('a['+i+']');
                    }
    
    
                    this.instantiators[length] = new Function('c', 'a', 'return new c('+args.join(',')+')');
                }
    
    
                return this.instantiators[length];
            },

    My edit:
    Code:
            getInstantiator: function(length) {
                if (!this.instantiators[length]) {
                    var emptyFn = function () {};
    
    
                    var instantiator = function (c, a) {
                        // create a "c" instance without calling the constructor
                        emptyFn.prototype = c.prototype;
                        var newCObject = new emptyFn();
    
    
                        // execute the constructor on the new object
                        // using the elements of "a" for arguments
                        c.apply(newCObject, a);
    
                        return newCObject;
                    };
    
    
                    this.instantiators[length] = instantiator;
                }
    
    
                return this.instantiators[length];
            },

    If we eliminate all Function constructors, we should get better performance, and the framework will work in Air again. Seems like all around goodness.
    Last edited by jeffm712; 11 Dec 2011 at 5:20 AM. Reason: forgot return statement

  2. #2
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    37,074
    Vote Rating
    854
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default


    Yes, we create a lot of magic functions but this gives the framework a unified API. For debugging, you can set a breakpoint at a line that executes one of these auto functions and we have worked to make the call stack correct.
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
    https://github.com/mitchellsimoens

    Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/

    Need more help with your app? Hire Sencha Services services@sencha.com

    Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is in print!

    When posting code, please use BBCode's CODE tags.

  3. #3
    Sencha User
    Join Date
    Dec 2011
    Posts
    2
    Vote Rating
    0
    jeffm712 is on a distinguished road

      0  

    Default


    OK. I'll of course defer to your guys' judgement. All I can say is, if you can find some other way to do the same thing, that would be tremendous. I've been playing with Adobe Air recently, and it's a shame to think that future versions of ExtJS can never be used.

  4. #4
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    37,074
    Vote Rating
    854
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default


    It seems to me that we have moved beyond Air... we have our own internal project call Ion that is a competitor to Air. Just what I have noticed.
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
    https://github.com/mitchellsimoens

    Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/

    Need more help with your app? Hire Sencha Services services@sencha.com

    Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is in print!

    When posting code, please use BBCode's CODE tags.

Thread Participants: 1