Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #18026
| From | "Leonardo Azpurua" <leonardo@exmvps.org> |
|---|---|
| Newsgroups | comp.lang.javascript |
| Subject | Request for opinions on my newbie approach |
| Date | 2013-01-08 22:24 -0430 |
| Organization | A noiseless patient Spider |
| Message-ID | <kcilrc$vt8$1@dont-email.me> (permalink) |
Hi,
Years ago I used to be a professional programmer, then I got totally spoiled
by VB6 (which I totally love, since it's the best tool so far to do what I
do), which I used to write a fairly large business management application
that has been paying my bills for over twelve years.
But now the time has come to move over, and after toying with several other
development tools and platforms, I decided to adopt HTML + ECMASCRIPT + CSS
on the client side and PHP for the server for any further development.
In order to simplify my work, I must simplify all the handling of DOM. And I
am in the process of writing libraries (for usage just by myself) that allow
me to preserve the blissful innocence won after twelve years using VB6.
Business apps are very much about transcribing and validating data. So there
are a lot of forms to be written, and I don't want to struggle with that
ugly DOM thing everytime.
The way to go seems to be to "encapsulate" as much as possible the DOM in
order to be able to get it out of my "operative" code.
Today I wrote my first attempt at a Form class, that will encapsulate an
HTML form and allow me to simplify the rest opf the code.
So far, this is all that I have done:
<file forma.js>
function Form(f) {
this.name = f.name;
for (var i = 0; i < f.elements.length; i++)
{
var e = f.elements[i];
this[e.id] = e;
this.addEventHandler(e, "blur");
this.addEventHandler(e, "focus");
}
}
Form.prototype.addEventHandler = function (dest, eventName) {
try {
dest.addEventListener(eventName, eval(dest.id + "_" + eventName),
false);
}
catch (e) {}
};
<file/>
And this is a possible use for it (the HTML file contains a form with two
TEXT HTMLinputElements; function initDocument is called by body.onload):
var laForma;
function initDocument() {
laForma = new Form(document.forms[0]);
}
function Text1_onblur()
{
laForma.Text2.value = laForma.Text1.value;
}
function Text2_onblur()
{
laForma.Text2.value = laForma.Text2.value.toUpperCase();
}
It "works", in the sense that when I leave Text1, its contents is copied
into Text2, and when I leave Text2, its contents is rendered in upper case,
and when any of the methods is undefined, nothing bad happens (not even an
error on FF JS console).
Of course this is going to "grow": depending of the type of the
HTMLformElements it is likely that different events will need to be handled
and browser compatibility issues will have to be solved. I just hope it
won't grow to be as bloated as most of the generally used libraries.
I am a rather "lonely" coder. So I decided to ask for your opinions to this
approach before going too much further.
TIA for any comments.
--
Back to comp.lang.javascript | Previous | Next — Next in thread | Find similar | Unroll thread
Request for opinions on my newbie approach "Leonardo Azpurua" <leonardo@exmvps.org> - 2013-01-08 22:24 -0430
Re: Request for opinions on my newbie approach Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-01-09 04:31 +0100
Re: Request for opinions on my newbie approach "Leonardo Azpurua" <leonardo@exmvps.org> - 2013-01-08 23:34 -0430
Re: Request for opinions on my newbie approach Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-01-09 05:14 +0100
Re: Request for opinions on my newbie approach Jim T. <x@y.z> - 2013-01-09 14:32 -0500
Re: Request for opinions on my newbie approach Cezary Tomczyk <cezary.tomczyk@gmail.com> - 2013-01-09 20:41 +0100
Re: Request for opinions on my newbie approach Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-01-09 21:03 +0100
Re: Request for opinions on my newbie approach Jim T. <x@y.z> - 2013-01-09 15:11 -0500
Re: Request for opinions on my newbie approach Luc Yen <luc@goal.tw> - 2013-01-09 14:38 -0800
Re: Request for opinions on my newbie approach "Leonardo Azpurua" <leonardo@exmvps.org> - 2013-01-09 18:10 -0430
Re: Request for opinions on my newbie approach Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-01-10 01:36 +0100
csiph-web