PDA

View Full Version : Namespace and setAlert



jriff
28 Jun 2009, 9:22 AM
Hi all

Normally people do this:

MyApp=new Ext.App();

then they can do:

MyApp.setAlert(response.success, response.message);


But I am doing this:

Ext.ns('MyApp');

But what do I do then? This doesn't work:

MyApp.setAlert(response.success, response.message);

Regards,

Jacob

elishnevsky
28 Jun 2009, 11:20 AM
Ext.ns() creates a namespace, which is essentially an empty object. It has no knowledge of setAlert() method.

elishnevsky
28 Jun 2009, 11:22 AM
What you can do is use Singleton Pattern.

MyApp = function() {
return {
setAlert: function() {
// method body goes here
}
}
}();
Now you can do MyApp.setAlert(...);

jriff
28 Jun 2009, 1:32 PM
Well - the setAlert method is actually a method that set an alert. It is a special Ext thing. With your suggestion I need to define it myself and that was not the idea. Maybe I have misunderstood the meaning of new Ext.App?

elishnevsky
28 Jun 2009, 2:14 PM
Perhaps I don't know something... setAlert() is a method of what Ext class?

mjlecomte
28 Jun 2009, 2:32 PM
If you are referring the the examples/shared/App.js file, that is just an example.

When other people do MyApp=new Ext.App(); that sets up a namespace MyApp as well.

Ext.namespace() just sets up an empty namespace. new Ext.App creates a new instance of a class that already contains a bunch of properties/methods.

jriff
29 Jun 2009, 3:55 AM
So does one replace the other or what? Should I be using "new App" instead of ns?

mjlecomte
29 Jun 2009, 5:44 AM
Ext.namespace() should just ensure the namespace, but not overwrite it. If you do myApp = 'foo' afterwards, it would replace myApp though.