Building a CMS - Object Oriented Code
(Page 4 of 5 )
Each document feature is going to need its own unique markup, so let's write a Javascipt object for each feature that will contain what we need for that feature, along with a method that will validate the form entry, and assemble the markup from the information gathered from the form.
These objects can have properties which are set when creating an instance of the object or left in their initialized state until they are set later. They also have public methods which are defined outside of the code block that defines the object but are declared as methods of the object by using the keyword "this."
//property set via the argument sent to the object
this.objectProperty = myProperty;
this.initializedProperty = false;
//establish myMethod as a method of this object
this.myMethod = myMethod;
if(this.myProperty > 0)
this.initializedProperty = true;
Once you have this code, all you need to do to use it is to create an instance of it. As in many programming languages that have object orientation you use the keyword "new."
//create an instance
var newObj = new myObject(2);
//invoke the instance's myMethod method
If you executed this code, you would get an alert box that would display the word "true."
More Web Hosting How-Tos Articles
More By Chris Root