What is the scope of javascript in firefox components?

I am creating a firefox component using javascript.
But I'm always confused by what is the global scope of the current javascript function, which leads to the following questions?

  • I understand the basic concept of the global scope of a js function in the normal case, but I want to know when the global scope of a function is defined? The time when the function is created (defined) or the time when the function is called?

  • Is there a way to show (print some information) the current global area of ​​the javascript function?

    following question is firefox component specific

  • For a firefox component, does each component have a global scope? (which means that each function of the component will be executed by itself global area), or all components have the same global area?
    If the same, what is it?

  • For example, in that case sorry for this boring example, i just make it as clear as possible.
    I am making a sandbox through Components.utils.Sandbox(<scope1>). I define some function in the ff component (I call <scope2>) and paste the variable into the sandbox: sandbox.external = this;("this" is just the component itself, which is in scope2 scope)
    After that I run some code in the sandbox Components.utils.evalInSandbox( <code> , sandbox);, and it <code>contains the function sandboxFoo()callingexternal.foo()

    1). What is the global scope sandboxFoowhen it starts? I think it should be

    2). external.foo, sandboxFoo? <scope1> <scope2>? ?

+3
2
  • . ( , ).
  • , , .
  • XPCOM , . , .
    • , , ( , , ). , .
    • . , this , . , this ( , ), , external.foo , .
+1
  • , .
  • , .
  • , . , .
  • , .
0

Source: https://habr.com/ru/post/1796230/


All Articles