Posts

Showing posts with the label jquery

Organizing Javascript codes with namespacing

Image
Usually when I build website each page has it's own Javascript file. But as the site grows I find it hard to maintain and code duplication is every where. After a few googling and research I found out that Javacript namespacing is the best way to organize and modularize your code. With my current hybrid app I have to constantly communicate with SQLite and that's how I realize I have to reuse code blocks to avoid spaghetti code. What I did is something like this. Let's break it down into pieces. Line one - we create a closure and import jQuery object so we can use it inside our namespace. You can remove the dollar sign ($) if you don't need it. Make sure you remove 'jQuery' at line 25 too. Line two - we declare a global object variable 'APP'. This is our namespace. Line four - we put a sub-namespace called SQL. Basically this a namespace inside a namespace. cool isn't. Line 5 - we declare a function named 'insert' with parameter ...