webtier@glassfish.java.net

Re: JSF 2.0: Errors or Ambiguity in Spec for "onevent" JavaScript Callback

From: <webtier_at_javadesktop.org>
Date: Wed, 30 Sep 2009 17:45:55 PDT

Ah, but both Prototype and jQuery use a completely different coding style - they're doing Object property declarations to set things up.

Thus, they say things like this:

ImportantClass.SubClass = {

propertyName1 : function(param, param) {},
propertyName2: function(param) {}

}

Which, while perfectly valid, is painful to read when switching back and forth between Java and JavaScript. And frankly, I find it a little painful to read even when I'm not switching.

So I far prefer:

var namespace = {};
namespace.functionName = function functionName(param, param) {
};

namespace.functionName = function functionName2(param) {
};


This does the same thing (sort of - we're avoiding objects, inheritance and prototypes like the plague in our code for a variety of reasons, some of which Crockford discusses), but it's also a little easier to read for Java-trained eyes.

It's like doing a name declaration, followed by a function name and function definition.

'Sides, function functionName() is just going to pollute your global namespace anyway, and we don't want that.

We made a conscious choice to make the JSF JS code not extend any object prototypes because we want to be able to be used with any library out there, BTW. Same thing with namespacing everything.
[Message sent by forum member 'driscoll' (jim.driscoll_at_sun.com)]

http://forums.java.net/jive/thread.jspa?messageID=366409