Wether you are hunting down bugs on a nasty prototype device or chasing a memory leak through a stack of browser libraries made in the last millenium - life of a developer takes a toll - so during down times you work out, eat right and try to recharge your batteries.
We've got this nice JavaScript namespacing solution. The general idea is pretty straitforward - namespaces are just objects. However coming from a Java background and being part of a large organization, we actually have namespaces containing namespaces and so forth.
In JavaScript, everything is an object. While consistent this comes at the price that things that you consider singular don't have any special features you usually expect from something singular. For instance, classes do not know their namespace or even their name. Even functions don't know their name (if you store them in a variable).
If you have go classes in a namespace tree these names still exist. They are keys of associative arrays somewhere in the tree. So here's what I did:
-
start from the root namespace object and store its name in a string
-
iterate through all the keys, append them to the parents namespace name (probably you want to put a "." or "::" in between.
-
store that name in the object. Its the fully qualified name of the ns/class
-
recurse until you hit a class or static (that's the leaf of your tree)
This way every class and namespace knows its fully qualified name. What can you use this for?
You could create a nice class diagram using graphviz or you can use it to serialize your code back into JavaScript. Sounds strange - is smart though: We have these complicated class creation functions that setup inheritance, super methods and copy keys around. The purpose of that is that we can write classes quite similarly to how you would do it in a OOP langugage. These class wrappers come at a penalty of initialization exection time. Plain pure prototypal classes are by factors faster. Through introspection and some code rewriting you can compile your javascript code into straitforward javascript code which will increase loading time.
To make people become truly educated people, must have three qualities: the knowledge, the habit of thinking and noble sentiment. Knowledge is not foolish, Not accustomed to thinking, is rude or stupid, No lofty sentiment, is humble.Do you think so?
Posted by: Asics shoes | 09/16/2010 at 02:25 AM
And do our best to improve this problem
Posted by: supra shoes | 11/08/2010 at 09:24 AM
*Nobody can stop the wheel of history.
Posted by: Replica Christian Louboutin Heels | 12/13/2010 at 03:16 AM
I thank thee that I am none of the wheels of power but I am one with the living creatures that are crushed by it. O(∩_∩)O~
Posted by: Air Jordan 13 | 12/25/2010 at 08:33 AM
That's not his. Steve's is black*_*
Posted by: Taobao English | 12/30/2010 at 03:30 AM
Failure is what I need, it is just as valuable to me and success
Posted by: replica louis vuitton | 01/12/2011 at 07:36 AM
Ooh baby, I love that Palenque comp. Great picks Jason!
Posted by: Taobao agent | 01/17/2011 at 04:09 AM
Ooh baby, I love that Palenque comp. Great picks Jason!
Posted by: Taobao agent | 01/17/2011 at 04:09 AM
wxodaE That's really thinking out of the box. Thanks!
Posted by: Marty | 04/09/2011 at 04:19 AM
BUrygy ofvtfusxqzmm
Posted by: bxqfazga | 04/21/2011 at 10:22 PM
This artclie achieved exactly what I wanted it to achieve.
Posted by: Lisa | 01/08/2012 at 04:47 PM