Threaded View

  1. #1
    Sencha User
    Join Date
    Sep 2012
    Posts
    65
    Answers
    7
    Vote Rating
    1
    warrean is on a distinguished road

      0  

    Default Answered: Extending class: set Scope when calling parent's methods

    Answered: Extending class: set Scope when calling parent's methods


    Hey,

    Why is the output of '1: ' not 'Parent'? How can I set the scope right?

    I can't use method '2:' because then I don't have access to any of the Refs neither!

    Code:
    Ext.define('Parent', {
     extend: 'Ext.app.Controller',
     getName: function() {
         return Ext.getClassName(this);
     }
    }
    Code:
    Ext.define('Child', {
        extend: 'Parent',
        doSomething: function() {
             console.log( '1: ' + this.getName() );
             console.log( '2: ' + this.superclass.getName() );
        }
    }

  2. This is how JavaScript works, the scope is the current scope which is the Child unless you change it with call or apply.

    Code:
    fn.call(scope, arg1, arg2);
    fn.apply(scope, [arg1, arg2])

Thread Participants: 1