Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Java-script Global NameSpace problem

1 view
Skip to first unread message

Vikram Baghel

unread,
Dec 30, 2009, 8:23:59 AM12/30/09
to
hello there !!
I've been restructuring one of my Firefox extension for global
namespacing. My java-script file looks something like this :-

--------------------------------------------------
var namespace = new function() {
return {
i: 0,
var: 'bar',

function1: function( ) {
alert("inside function 1");
namespace.function2( );},

function2: function( ) {
var j = 0;
alert("inside function2"); }
};
}
------------------------------------------------
when i invoke namespace.function1(), i get this error in Error
Console ::

Error: namespace is not defined
Source file: chrome://browser/content/browser.xul
Line: 1

please let me know where im going wrong !!
- Thanks in advance

Sébastien Lorquet

unread,
Dec 30, 2009, 8:34:42 AM12/30/09
to dev-ext...@lists.mozilla.org
Hi,

I'm not very experimented in js, but I would have done:

namespace.prototype.function1 = function() {
.....
}
namespace.prototype.i = 0;

etc.

is that different from what you are requesting?

regards
seb

> _______________________________________________
> dev-extensions mailing list
> dev-ext...@lists.mozilla.org
> https://lists.mozilla.org/listinfo/dev-extensions
>

John J. Barton

unread,
Dec 30, 2009, 10:53:24 AM12/30/09
to
Sébastien Lorquet wrote:
> Hi,
>
> I'm not very experimented in js, but I would have done:
>
> namespace.prototype.function1 = function() {
> .....
> }
> namespace.prototype.i = 0;
>
> etc.

Or even simpler,

var namespace =
{
function1: function()
{
};
};

jjb

0 new messages