On 1/9/06, Simon Kitching <[EMAIL PROTECTED]> wrote:
This would be the very bare minimum. Much more useful is to introduce something similar to the Java package system, which is what Dojo does, for example. So then you have packages such as dojo.lang, dojo.io, dojo.widget.html, etc. As with Java, you then define your classes inside those packages. (One of the things that's quite different from Java, though, is that the 'this' keyword means something very different in _javascript_, even when it appears to be the same in the simplest cases.)
There's a discussion of namespacing in _javascript_ at the end of this excellent article about "OOP with ECMAScript":
http://fm.dept-z.com/index.asp?get=/Resources/OOP_with_ECMAScript/
--
Martin Cooper
Adam Winer wrote:
> One
> of the items already on our todo list is moving all the functions,
> classes, and variables inside a single top level object.
Using a single top-level object is something I've been considering
suggesting for a while.
MyFaces could create a single "myfaces" object for _javascript_, then
attach any further scripting to that object as "methods". This reduces
the namespace pollution to a single name.
This would be the very bare minimum. Much more useful is to introduce something similar to the Java package system, which is what Dojo does, for example. So then you have packages such as dojo.lang, dojo.io, dojo.widget.html, etc. As with Java, you then define your classes inside those packages. (One of the things that's quite different from Java, though, is that the 'this' keyword means something very different in _javascript_, even when it appears to be the same in the simplest cases.)
There's a discussion of namespacing in _javascript_ at the end of this excellent article about "OOP with ECMAScript":
http://fm.dept-z.com/index.asp?get=/Resources/OOP_with_ECMAScript/
--
Martin Cooper
Of course components can create their own "object", and attach it to the
global myfaces object as a member, and then hang their methods off that
object to avoid possible name collisions with other components.
myfaces = new Object();
myfaces.submitForm = function() {......}
myfaces.ajax = new Object();
myfaces.ajax.someMethod = function() {.....}
>
Adam: is this what you meant?
Regards,
Simon
