Matt R.Warren of Contegra
Yes, believe it
exceptionally powerful one mind. And ok, it may not be a ‘full’ OOP language
with inheritance, interfacing etc… like C++/C# or Java. However, saying that,
browsers DOM in an OOP based hierarchal manner, so why not your own controls
So why create an
object at all? In fact, what is an object. Simply put, an object (in programmer
speak) is a way of encapsulating data and functionality into a (more-or-less)
stand-alone unit that is essentially re-useable. This is exceptionally useful.
It allows you to group data and functionality logically, or in the case of this
small example, render to the browser a simple control multiple times… and
all instances of the object are all independant from each other.
Just some things
you need to keep in mind. the DOM has some restrictions. It is hard to uniquely
identify individual tags if they all share the same ID’s or NAME’s. This is
a potential problem as effectively we are trying to create form controls that
function independantly. Usually to avoid this problem I create an ‘index’ that
is handled purely from within my object definition. However this approach is
a little complicated and is beyond the scope of this small tutorial. Saying
that however, we still need some way of creating individuality within the DOM,
so for the purposes of this example I am using a very cut down version of what
I usually use and I have created a globally scoped variable called ‘myObjectIndex’.
It’s usage is examplained later.
are fairly flexible beasts. They don’t just allow you to run small segments
of procedurised code. They are also used to form the skeletal framework you
require to create an object. Lets go through the example and I will explain
what it happening as I go. (all explanations are in comment form)…