ExtJS – Using Namespaces Improved

Aaron Conran of ExtJS just published a post today recommending using namespaces to organize your Javascript code. I have a rewrite of the Ext.namespace function that I find a little more useful.

I wanted to do 2 things. Firstly I wanted to be able to do this: (it saved typing)

So, as you can see, I save a lot of typing when calling superclass methods. By returning the namespace from my custom Ext.namespace function (source at the bottom of this post) I am able to do this.

I also wanted to be able to apply “namespaces” to custom objects. For example, if I needed to build out a simple javascript object ensuring that a path of properties exist like so:

The above code is a trivial example. I really use it to construct objects that are parseable by a JsonReader given the JsonReader’s configuration. I won’t get into why I do this… but I will just say it involves on-demand store loading from a tree datasource based on tree node expansions.

Please consider this code as a replacement for the default Ext implementation:

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">