1. #1
    Touch Premium Member
    Join Date
    Nov 2010
    Location
    Chicago
    Posts
    1,311
    Vote Rating
    109
    LesJ is a glorious beacon of light LesJ is a glorious beacon of light LesJ is a glorious beacon of light LesJ is a glorious beacon of light LesJ is a glorious beacon of light LesJ is a glorious beacon of light

      0  

    Default Base.js - override example question

    Base.js - override example question


    See the override example from Base.js.

    The constructor returns an instance. Is this required? It works fine if the constructor has no return value.

    Code:
    Ext.define('My.Cat', {
       constructor: function() {
           alert("I'm a cat!");
       }
    });
    
    
    Ext.define('My.CatOverride', {
       override: 'My.Cat',
       constructor: function() {
           alert("I'm going to be a cat!");
    
           var instance = this.callParent(arguments);
    
           alert("Meeeeoooowwww");
    
           return instance;
       }
    });
    Also, the default constructor returns this, but I don't see that subclasses (e.g. components) return this, so why does the default constructor return this? Should the default constructor be an empty function?

    Code:
    // Default constructor, simply returns `this`
    constructor: function() {
        return this;
    },
    Ext.ClassManager has multiple inline examples where the constructor returns this.
    Last edited by LesJ; 7 Feb 2012 at 8:44 AM. Reason: Add Ext.ClassManager info

  2. #2
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    36,801
    Vote Rating
    834
    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


    if you do

    Code:
    new Ext.Component({...});
    It returns the instance which is what constructor does.
    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
    Touch Premium Member
    Join Date
    Nov 2010
    Location
    Chicago
    Posts
    1,311
    Vote Rating
    109
    LesJ is a glorious beacon of light LesJ is a glorious beacon of light LesJ is a glorious beacon of light LesJ is a glorious beacon of light LesJ is a glorious beacon of light LesJ is a glorious beacon of light

      0  

    Default


    Quote Originally Posted by mitchellsimoens View Post
    if you do

    Code:
    new Ext.Component({...});
    It returns the instance which is what constructor does.
    Is this (simpler code) the correct way to override My.Cat?

    Code:
    Ext.define('My.Cat', {
       constructor: function() {
           alert("I'm a cat!");
       }
    });
    
    
    Ext.define('My.CatOverride', {
       override: 'My.Cat',
       constructor: function() {
           alert("I'm going to be a cat!");
    
           this.callParent(arguments);
    
           alert("Meeeeoooowwww");
       }
    });
    
    new My.Cat()

  4. #4
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    36,801
    Vote Rating
    834
    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


    If you are overriding, you should use callOverridden instead of callParent. Not sure if that makes much of a difference though and has been deprecated in ST2
    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.

  5. #5
    Touch Premium Member
    Join Date
    Nov 2010
    Location
    Chicago
    Posts
    1,311
    Vote Rating
    109
    LesJ is a glorious beacon of light LesJ is a glorious beacon of light LesJ is a glorious beacon of light LesJ is a glorious beacon of light LesJ is a glorious beacon of light LesJ is a glorious beacon of light

      0  

    Default


    Quote Originally Posted by mitchellsimoens View Post
    If you are overriding, you should use callOverridden instead of callParent. Not sure if that makes much of a difference though and has been deprecated in ST2
    This is an inline Sencha example (not my code) and it calls callParent, not callOverriden.

    I'm also confused about this inline example from ClassManager. I modified this example. I'm not returning this from the constructor and it works just as well. Is returning this from constructor required?

    Please clarify if I should return this from the constructor when I extend or override a class.

    Code:
    Ext.define('Person', {
           name: 'Unknown',
    
           constructor: function(name) {
               if (name) {
                   this.name = name;
               }
    
               // return this;
           },
    
           eat: function(foodType) {
               alert("I'm eating: " + foodType);
    
               return this;
           }
      });
     
     var aaron = new Person("Aaron");
     aaron.eat("Sandwich"); // alert("I'm eating: Sandwich");
     
    
    Ext.define('Developer', {
       extend: 'Person',
    
       constructor: function(name, isGeek) {
           this.isGeek = isGeek;
    
           // Apply a method from the parent class' prototype
           this.callParent([name]);
    
           // return this;
       },
    
       code: function(language) {
           alert("I'm coding in: " + language);
    
           this.eat("Bugs");
    
           return this;
       }
    });
    
     var jacky = new Developer("Jacky", true);
     jacky.code("JavaScript")

  6. #6
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    36,801
    Vote Rating
    834
    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 personally never return anything in my constructors and have had zero issues in creating extensions or overrides.
    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.

  7. #7
    Touch Premium Member
    Join Date
    Nov 2010
    Location
    Chicago
    Posts
    1,311
    Vote Rating
    109
    LesJ is a glorious beacon of light LesJ is a glorious beacon of light LesJ is a glorious beacon of light LesJ is a glorious beacon of light LesJ is a glorious beacon of light LesJ is a glorious beacon of light

      0  

    Default


    Quote Originally Posted by mitchellsimoens View Post
    I personally never return anything in my constructors and have had zero issues in creating extensions or overrides.
    OK I won't let these examples bother me

Thread Participants: 1

Turkiyenin en sevilen filmlerinin yer aldigi xnxx internet sitemiz olan ve porn sex tarzi bir site olan mobil porno izle sitemiz gercekten dillere destan bir durumda herkesin sevdigi bir site olarak tarihe gececege benziyor. Sitenin en belirgin ozelliklerinden birisi de Turkiyede gercekten kaliteli ve muntazam, duzenli porno izle siteleri olmamasidir. Bu yuzden iste. Ayrica en net goruntu kalitesine sahip adresinde yayinlanmaktadir. Mesela diğer sitelerimizden bahsedecek olursak, en iyi hd porno video arşivine sahip bir siteyiz. "The Best anal porn videos and slut anus, big asses movies set..." hd porno faketaxi