The web is evolving, and the way that we use JavaScript to build websites is evolving too. It's important to understand what JavaScript offers, and how to use its capabilities to stay ahead of the curve.
History of JavaScript
JavaScript was invented by Netscape in 1996, just 5 years after the first webpage was created (click here to see the history of web pages and search engines). JavaScript's purpose was to enhance web pages by adding small browser side functionality to dynamically modify text on the screen. Once CSS became standard in 1997, JavaScript 1.2 allowed developers to dynamically change CSS styles with event listeners.
How JavaScript is used today
It is now 2010, and most developers use JavaScript in the same way that people used it over ten years ago. As websites become more dynamic and more programming logic is executed in the browser (making the web application seem more and more like a desktop application), the amount of JavaScript being used goes through the roof.
How to use JavaScript Objects
To define an object, just create a function that looks like this:
function person(name, age, sex) {
this.name=name;
this.age=age;
this.sex=sex;
}
To instantiate an object, do this:
var jane=new person("jane", 22, "female");
alert("hi " + jane.name + "!");
Using JavaScript objects will allow you to easily create and modify data being stored for a given webpage.
How MVC architecture is changing
In MVC architecture (the standard architecture for software applications) the data model objects and view objects have been traditionally located on a web server, where the html for a webpage is created and then sent to the client machine. As web applications move towards RIA's (rich internet applications), the MVC architecture of web applications is changing in such a way that the view objects are being moved to the client side (the browser). That being said, I find it hard to believe that a lot of people don't utilize JavaScript's ability to handle custom defined objects.
If you are developing web pages that use a lot of heavy DHTML, I fully recommend that you start treating your JavaScript code as the "view" in the MVC architecture model, and handle the data on your screen with objects! I'tl make your JavaScript code much cleaner and more versatile.
Good Luck!
Source by Eric D Rowell
Post a Comment
Click to see the code!
To insert emoticon you must added at least one space before the code.