extjs - Ext.define confusion -


i'm having issue makes me think might misinterpreting use of extjs class architecture bit. herewith example of simplified version demonstrates issue

        ext.define('person', {             name : 'default',             inventory : [],             addinventoryitem : function(item) {                 ext.array.push(this.inventory, item);             },             inventorylist : function() {                 console.log("inventory: " + json.stringify(this.inventory));             },             setname : function(name) {                 this.name = "name";             }         });          ext.define('student', {             extend : 'person'         });          alex = ext.create('student');         alex.setname("alex");         alex.addinventoryitem("knifes");         alex.inventorylist();          david = ext.create('student');         david.setname("david");         david.addinventoryitem("forks");         david.inventorylist(); 

output:

inventory: ["knifes"] inventory: ["knifes","forks"] 

expected output:

inventory: ["knifes"] inventory: ["forks"] 

i would've expected actual result in event of overriding class, fail understand why second instance affects superclass, , in turn reflects changes made first instance.

the problem there single inventory array shared between instances of class. array created once @ time class defined, each instance gets reference 1 array.

basically need give each person instance own inventory array on creation, this:

ext.define('person', {   ...   constructor: function() {     this.inventory = [];   },   ... }); 

Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -