1. #1
    Sencha User
    Join Date
    Nov 2010
    Posts
    17
    Vote Rating
    0
    sim4life is on a distinguished road

      0  

    Default Unanswered: Javascript var scoping in Migration to 2.x

    Unanswered: Javascript var scoping in Migration to 2.x


    I have an application working in Sencha Touch 1.x and I'm looking migrate it to Sencha Touch 2.x. I've followed the guide and done with the basic part. However, I found this problem in console:
    Code:
    TypeError: 'undefined' is not a function (evaluating 'User.getLoginFormBase(loginHandlerCB)')
    index.js 119
    This function is called from index.js as
    Code:
    Ext.setup({ 
    //...    
        onReady: function() {
    loginHandlerCB = function(ele, eve) {
    //... }; registerLoginHandler = function() { loginFormBase = User.getLoginFormBase(loginHandlerCB);
    };
    } });
    while this function is defined in file mobile,js as
    Code:
    var User = {
        getLoginFormBase: function(loginCB) {
    //...
    }
    It used to work fine in Sencha Touch 1.x. So in ST2, is there a basic difference in javascript variable scoping or in starting the application using Ext.setup() and putting everything inside it?

  2. #2
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    37,347
    Answers
    3542
    Vote Rating
    846
    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


    I'd create a utility class:

    Code:
    Ext.define('User', {
        singelton : true,
    
        getLoginFormBase: function(loginCB) {...}
    });
    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