View Full Version : [CLOSED] Feature request: Ext.namespace should return created object
ziesemer
27 Mar 2008, 11:32 PM
Suggestion for a quick enhancement to the Ext.namespace function. Could it return the object it created?
Example, right now I might have the following:
Ext.namespace("com.ziesemer.namespaceExample");
com.ziesemer.namespaceExample.example1 = function(){
...
}();
Instead, it would be nice to do the following:
Ext.namespace("com.ziesemer.namespaceExample").example1 = function(){
...
}();
After reviewing the Ext.js source, I found that simply adding "return o;" as the last line seems to accomplish this nicely, though it only returns the last (or only) namespace created. (Alternatively, if multiple namespaces are passed in, maybe an array of the results could be returned.) This works whether the "namespace"/object is created newly or not.
Please consider including this in the next release?
Thanks!
mystix
28 Mar 2008, 12:08 AM
:> and what happens / what should happen when someone decides to create multiple namespaces at a go using Ext.namespace()?
like so
Ext.namespace("old", "macdonald", "had", "a", "farm");
:-?
ziesemer
28 Mar 2008, 10:53 AM
I already considered this in my original post. As I stated above, either:
1) Just return only the last namespace that was created, and document it as such. This would require only the one line patch, at really no performance/memory expense. It's better than nothing.
2) Otherwise, consider returning an array of the created objects if multiple namespaces were requested.
JeffHowden
28 Mar 2008, 9:48 PM
I already considered this in my original post. As I stated above, either:
1) Just return only the last namespace that was created, and document it as such. This would require only the one line patch, at really no performance/memory expense. It's better than nothing.
2) Otherwise, consider returning an array of the created objects if multiple namespaces were requested.
Despite your single example, I see no benefit to adding this. Can you elaborate why this is better than the it is right now?
mystix
28 Mar 2008, 10:53 PM
me neither.
for one, it isn't intuitive.
plus, all that does is save you from writing the portion in bold:
Ext.namespace("old.macdonald.had.a.farm");
old.macdonald.had.a.farm = function() {
// ... eee eye eee eye oh
}
doesn't help me one bit if all i want is to hang something off old.macdonald.
:-?
halkon_polako
29 Mar 2008, 3:46 AM
Me neither...it can be confusing. I see Ext.namespace(...) as a declaration (only need to be declared one time).
Once the namespaces are declared, then you can use it... so they are two diferent things.
ziesemer
29 Mar 2008, 5:44 AM
It's a potential one-line code addition that could save a bit of "copy & paste" work when creating namespaces.
It was a suggestion that I think would still be a good idea, but clearly no one else thinks so.
Thanks for your consideration.
brian.moeskau
29 Mar 2008, 11:50 PM
Hi ziesemer,
Thanks for the suggestion. I have to agree with others that the benefit is not quite there. The small savings in typing might be outweighed by the potential confusion/complexity when adding multiple namespaces. It seems like a small change, but the benefit still has to outweight the "cost."
Powered by vBulletin® Version 4.1.5 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.