I am making a firefox component using javascript.
But i am always confused about what is the global scope of the current javascript function, which results in the following questions?
I understand some basic concept about global scope of js function in normal case, but i want to know, when is the global scope of a function determined? The time when function is created(defined), or the time when the function is called?
Is there a way to show(print some information) the current global scope of a javascript function?
following question is firefox component specific
For firefox component, does each component have a global scope itself? (which means each function of the component will be run in itself global scope ), or every components have the same global scope?
If same, what's that?
For example, in such case
sorry for this boring example, i just make it as clear as possible.
I make a sandbox via Components.utils.Sandbox(<scope1>)
. I define some function in a ff component( i called <scope2>
) ,and inject a variable in to sandbox by : sandbox.external = this;
( "this" is just a component itself, which in a scope2 )
After these step, i run some code in sandbox by Components.utils.evalInSandbox( <code> , sandbox);
, and <code>
contains a function sandboxFoo()
that call external.foo()
1). what's the global scope of sandboxFoo
when it is running? I think it should be
2). what's the global scope of external.foo
when it is called by sandboxFoo
? Is it the <scope1>
or <scope2>
? Any documentation?
this
points to when you assign it. Assuming that this
is the global scope of your component (it likely won't be as written), and that you mean that you call external.foo
from within the sandbox, the global scope will be your components global scope.