I'm new in sencha touch and javascipt and i'm trying to init a value in function of others values in my sencha touch model. In java, I do this :
private int a,b,c;
public className(int a, int b){
this.a = a;
this.b = b;
this.c = b - a;
}
In sencha i've tried to do that but i've an "Uncaught TypeError: Cannot call method 'hasOwnProperty' of undefined". Here is my model :
Ext.define('MyApp.className', {
extend: 'Ext.data.Model',
config: {
fields: [
{ name: 'a', type: 'int' },
{ name: 'b', type: 'int' },
{ name: 'c', type: 'int'},
]
},
constructor: function(config) {
var a = this.get('a');
var b = this.get('b');
this.set('c', b - a);
},
});
And here how I create my instance :
var instance = Ext.create('MyApp.className', {
a : '5',
b : '4'
});
I've tried to replace my method name from contructor to init, and now it works. But I don't know if it's the right way to do that, because the init function is not the constructor... What's the difference ? How write a constructor ?
Thanks per advance !