View Full Version : Class declaring

21 May 2012, 10:05 AM
I have written this code in app.js (copy from documentation)

Ext.define('User', {
extend: 'Ext.data.Model',
fields: [
{name: 'name', type: 'string'},
{name: 'age', type: 'int', convert: null},
{name: 'phone', type: 'string'},
{name: 'alive', type: 'boolean', defaultValue: true, convert: null}

changeName: function() {
var oldName = this.get('name'),
newName = oldName + " The Barbarian";

this.set('name', newName);

var user = Ext.create('User', {
name : 'Conan',
age : 24,
phone: '555-555-5555'

user.get('name'); //returns "Conan The Barbarian"

and get error
GET http://localhost/User.js?_dc=1337622188229 404 (Not Found) /ext/ext-debug.js:5635
Uncaught TypeError: object is not a function

I don't know why, when create Class extjs is trying load User.js, because before I already declared class User

21 May 2012, 12:02 PM
Well, that is not what it's said to be in app.js

You are basically defining a User.js model by extending the ExtJS.data.Model class. Read the MVC tutorials and Class system. Those docs will tell you that app.js will have a launch().

ExtJS is looking for User.js because you are telling it to look for a file named User.js

http://docs.sencha.com/ext-js/4-1/#!/guide (http://www.sencha.com/learn/the-mvc-application-architecture/)

21 May 2012, 12:39 PM
Yes, I know if I use the same name for js file this should work.
But I will to know how it works(algorithm)

For example:
1. Define and extend any EXT JS class
2. Class have to have the same name as js
3. Class file have to have only one extended class per file

Actualy looks like, Ext js class is not the same class like for example in C++ or PHP >= 5.3 and always should be one class per file or mayby not? maybe is other option? I would like to know more about this matter.

After reading http://www.sencha.com/learn/the-class-system/ point 1.2 I suppose that create method is special and it is not only create object (like in c++). It also loading file, make getters and setters etc.

Am I correct?