Tuesday, May 3, 2011

Planning for the Future

When writing javascript classes think about what functionality you use most often. Allot of functions can be reused, and will speed development time by packaging them into a class object.

If you are just starting out it may be tough to get your head around javascript classes, but they really aren't that difficult. See my previous blogs about javascript classes.

Form fields are one of the many things that can be packaged and reused. Just check each object to see if it exists on the page, before declaring it, otherwise the browser will object. Functions like one used to get a parameter from an url, or to change the properties of an object on the page can also be packaged.

If you are not using classes, and you are just adding functions to your javascript file as needed, you will eventually run into a rat's nest. The more code you add, the more complicated it gets, and it takes longer and longer to track down a problem.

Some of my projects have javascript files of over 1000 lines of code, and I am now using classes to try and simplify my coding, and make it easier to find things. If you need help, there are lots of places you can go on the Internet to find information about coding javascript classes.

One think to remember is that you must call a method via a function, and you can not just declare a reference to the object you are using.

If you try to declare a public reference to the object, IE will accept it and Mozilla browsers won't. I just use a function called bind with a bunch of case statements to evaluate a parameter, and call the appropriate method.

Packaging up your functions makes allot of sense, especially on projects that use allot of dynamic data. Most websites you design will probably need allot of special functionality to access data, and will add up.

If you put everything into classes, and someone has to go through your code, then they will be able to understand it just as well as you.

No comments:

Post a Comment

Programming for the Web