NNKL.COM
welcome to my space
X
Search:  
 HOME   [JS] Global variable
[JS] Global variable
Published by: anonym 2009-01-09
Welcome to:nnkl.com

  • Hi, this is very simpy question :">

    Example = new Ext.app.App({

    permissions: 15, // FIRST

    init : function(){

    Ext.QuickTips.init();

    Ext.Ajax.request({

    url : 'index.php?permissions=check',

    success: function ( resp, opt ) {

    this.permissions = 5; // SECOND


    }

    });
    }

    });

    Example.MainMenu = Ext.extend(Ext.app.Module, {
    init : function(){
    alert(Example.permissions);// I'm see 15, but want to see 5. HowI can make this var public?
    }
    });

    Thanks.


  • If you're instantiating Ext.app.App class you cannot have private variables w/o changing the class you instantiate. The code in this case would be:


    Example = new Ext.app.App({
    permissions: 15, // FIRST
    init : function(){
    Ext.QuickTips.init();
    Ext.Ajax.request({
    url : 'index.php?permissions=check',
    scope : this,
    success: function ( resp, opt ) {
    this.permissions = 5; // SECOND
    }
    });
    }
    });
    Example.MainMenu = Ext.extend(Ext.app.Module, {
    init : function(){
    alert(Example.permissions);// I'm see 15, but want to see 5. HowI can make this var public?
    }
    });
    If you just need some object to hold privileges and to keep variable private you should do something like this:


    Example.Perm = function() {
    var permissions = 15;

    return {
    init : function(){
    Ext.QuickTips.init();
    Ext.Ajax.request({
    url : 'index.php?permissions=check',
    success: function ( resp, opt ) {
    permissions = 5; // SECOND
    }
    });
    },
    getPermissions : function() {
    return permissions;
    }
    };
    }();

    alert(Example.Perm.getPermissions());


  • OK. I'm using last construction. But always returned `15`, because ajax-reguest executed after `alert(Example.Perm.getPermissions());`
    Thanks!


  • Thanks for reply, Saki!
    I reading Public, Private, Privileged (http://extjs.com/learn/Tutorial:Application_Layout_for_Beginners#Public.2 C_Private.2C_Privileged.3F) but there declaring public var in the `return` operator, but I need to set var in the AJAX-operator body.
    Thanks.


  • What is that Scope all about (http://extjs.com/forum/../learn/Tutorial:What_is_that_Scope_all_about)
    Application Layout for Beginners (http://extjs.com/forum/../learn/Tutorial:Application_Layout_for_Beginners)


    Javascript tries to find var in nearest scope, then upper, upper, .... global.





  • I Am a Sinner – What About You?
    Global Sourcing and Supplier Online by Dylan

    You are looking at:nnkl.com's [JS] Global variable, click nnkl.com to home
  • updating problem
  • visualisation dissapears when try to change
  • upgrading problem
  • how do you refresh the app program emulation list
  • new dvd menu feature
  • streaming dvd over local network
  • xbmc shows 39 not connected 39 to internet
  • dvd player a knight 39 s tale locks up xbmc
  • dvd player locks up on iso images
  • remote networking stream over internet
  • can not use webrowser in new 13 09 2005 xbmc with
  • network not connected during boot
  • xbmc has the option to change the ledcolor
  •  
  • add current weather news info at xbmc home window
  • where is album info stored
  • rar no longer shows in myvideos filelist
  • xbox wireless g no connection
  • mymusic screen not masking out video extensions
  • network behind a switch
  • attempting to edit ip address causes lock up
  • problem with subtitles
  • help xbmc
  • problem with ccx bookmarks
  • xbmc 2005 08 30 t3ch
  • thumbnail removal
  • imdb help for the daft
  •  Homepage | Add to favorites | Contact us | Exchange links | LOGIN | Site map | 
    Copyright© 2008 nnkl.com        Site made:CFZ