javascript - Accessing private attribute within the class -


why following code not work (extjs v6)?

ext.define('test', { extend: 'ext.window.window', xtype: 'basic-window',  config: {     mytitle: '' },  constructor: function (config) {     ext.apply(this, config);     this.callparent(config); },  requires: [            'ext.form.panel'        ],  height: 300, width: 400, scope: this,  title: 'title: ' + this.mytitle, autoscroll: true, autoshow: true, bodypadding: 10, html: "lorem ipsum", constrain: true, });  var t = ext.create('test', {mytitle: 'testtitle'}); t.show(); 

i expect sets title of window "title: testtitle". instead, sets title "title: undefined".

add-on: if use

... title: 'title' + this.getmytitle(), ... 

i "uncaught typeerror: this.getmytitle not function". why?

first problem when title: 'title: ' + this.mytitle evaluated, this not point instance of class. should constructor

also call callparent expects array of arguments, it's easier call this.callparent(arguments)

lastly can call this.getmytitle() after you've called constructor.

see https://fiddle.sencha.com/#fiddle/uh9

constructor: function(config) {     this.callparent(arguments);     this.settitle( 'title: ' + this.getmytitle() )                       }, 

about configs correct way respond config being set

by implementing updatemytitle, work whenever calls setmytitle('title')

https://fiddle.sencha.com/#fiddle/uha

ext.define('test', {     extend: 'ext.window.window',     xtype: 'basic-window',     requires: ['ext.form.panel'],     config: {         mytitle: ''     },      updatemytitle: function(mytitle) {         this.settitle('title: ' + mytitle);             }, 

Comments