Javascript and Namespaces...

Say you want to trigger the submission of a form in jquery:

$("form.someclass").submit();

Simple, straightforward, robust... you think.  Turns out in Firefox, if you have any form element (such as your submit button) named "submit", the submit referenced becomes that element, rather than the function to do the submission.

OMG, you think, has no-one thought to have namespaces in this mess of an environment.  But whatever, you think, it's one little WTF in a field full of WTFs.  Let's just test this puppy and head off to bed.

But it doesn't work on Chromium even with your renamed submit buttons?  How?  Well, in Chromium you also have to avoid having any elements with an *id* of "submit", or they too override the submit function.

Reminds me of 3D libraries designed for newbie users.  Throw absolutely everything, colours, textures, coordinates, indices, etceteras into a single grab-bag with half a dozen aliases for everything.  As you move to more and more complex scenes you start hitting namespace issues where the natural name for X and the natural name for Y are now in conflict and you have to come up with rules to keep them apart when passed into the top-level "object" constructor.

Anyway, just wanted to vent.

Comments

  1. John Drinkwater

    John Drinkwater on 07/11/2009 3:23 a.m. #

    I believe the [].element usage is implemented in browsers due to *that* certain browser having it and there being an expectation of use from ignorant developers..
    At least the tail should stop wagging the dog soon.

Comments are closed.

Pingbacks

Pingbacks are closed.