what's the javascript function scope in firefox components?

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?

  1. 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?
  2. Is there a way to show(print some information) the current global scope of a javascript function?

    following question is firefox component specific

  3. 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?
  4. 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?

-------------Problems Reply------------

  1. The global scope of a function is figured out when you define a function. In the case of components, the global scope is shared with everything in the file (most of the time, you'll only have one component per file, so that component effectively gets its own global scope).
  2. This really depends on what you want to know, and how your function was called.
  3. The global scope of an XPCOM component is going to be the file it is defined in. If you have more than one component defined in the file (uncommon), they will share the same global scope.
    1. I think you mean what is the global scope when running code inside the sandbox (your question is vague, but I can revise this if I'm wrong). When you create a sandbox, it creates a new global scope for the sandbox.
    2. This is a bit more complicated. It's a reference to whatever 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.

  1. The scope is established when the function is defined.
  2. Sorry, don't know of any.
  3. The scope depends on what you are overlaying. If two components are overlaying the same element, they have the same scope.
  4. The global scope will be the one in which it was defined.
Category:javascript Views:0 Time:2011-03-04

Related post

  • Extending javascript function scope 2012-04-03

    Is it possible to extend dynamically javascript function scope? I tried without success the following: function foo() { var bar = 12; return function(x) { return eval(x); } } var e = foo(); console.log(e("bar")); // 12 console.log(e("bar = 42;")); //

  • How do I execute a page-defined JavaScript function from a Firefox extension? 2008-09-30

    I'm creating a Firefox extension for demo purposes. I to call a specific JavaScript function in the document from the extension. I wrote this in my HTML document (not inside extension, but a page that is loaded by Firefox): document.funcToBeCalled =

  • Scoping Out the Javascript Function Scope Problem 2011-05-28

    It's very clear I don't understand how functions are scoped in Javascript. Here's the latest example: function riseData() { var jsonResult; $.ajax({ success: function(data, textStatus, jqXHR){ jsonResult = jqXHR.responseText; alert("Inside: " + jsonR

  • JavaScript function scope between script tags 2012-04-23

    I have two different JSPs that the Java backend concatenates together and sends back to the same rendered HTML page. Each JSP has its own <script> block and defines functions inside that block: JSP #1: <script type="text/javascript"> func

  • jQuery / JavaScript Function Scope / Hoisting 2015-01-26

    I have two files containing JavaScript and jQuery functions. They are referenced on the page in this order: <script src="js/kiosk-functions.js"></script> <script src="js/kiosk-main-socket-handler.js"></script> In kiosk-functio

  • Dynamic add row javascript function works in Firefox but not in IE 2009-05-28

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> <title>:: Gharsansar Spices Order Form ::</title> <script language="javascript" t

  • Cross-browser Javascript Function Scope Issue 2011-11-17

    The following javascript works in Chrome and IE but errors out in Firefox because bar is undefined when assigned to callBar. So who got their scope rules right? function foo() { var callBar = bar; if (1 === 1) { callBar(); function bar() { alert('yo'

  • JavaScript function scope question 2011-09-09

    Please refer to the following code function createCar(sColor, iDoors, iMpg) { var oTempCar = new Object; oTempCar.color = sColor; oTempCar.doors = iDoors; oTempCar.mpg = iMpg; oTempCar.showColor = function () { alert(this.color) }; return oTempCar; }

  • Javascript Function Scope 2009-08-12

    This is perhaps a dumb question, but I am new to Javascript and desperate for help. If the Javascript engine will look for global variables outside of a function, then what is the point of passing parameters to it? What do you gain? I understand that

  • Yet another javascript function scope question 2010-10-20

    In this code, the ident and data variables are correct in the callback, but I don't know how to pass in the right i for each loop iteration. I've tried reading up on functions and tried like 10 things, but alas, I must seek the wisdom of the stack. f

  • Javascript function scope issues 2010-11-27

    I'm working on a little Websockets demo and I've got a scope issue I can't sort. network = function () { this.host = "ws://localhost:8002/server.js"; this.id = null; this.init = function (s) { var scene = s; try { socket = new WebSocket(this.host); s

  • javascript function scope and overwriting 2012-01-31

    I have some javascript like this: <script> var num = 0; if(num==0){ function lol(){ alert("lol"); } } else { function lol(){ alert("haha"); } } </script> Then, later in the page I have: <script>lol();</script> How do I ensure

  • javascript, function scope - global variable NaN 2012-03-14

    I am having a hard time with these three interactive functions. The fist gathers values from a form and uses it with some variables set outside the function /* -------------------- Varibales set for use through script --------- */ var price_set =

  • How to find out what event cause a javascript function to be executed in FireFox? 2009-05-15

    I'm debugging an old Infragistic grid. One of the javascript functions executes more times than needed. It was coded to be executed when a user clicks a cell in the grid. However, sometimes it runs when on mouse is over the cell. I'd like to know if

  • JavaScript function works fine in Opera but doesn't work at all in Firefox. Why? 2009-09-15

    This is my JavaScript function: function switch_div(firstID,secondID) { if((document.getElementById(firstID).style.display == 'inline') && (document.getElementById(secondID).style.display == 'inline')) { document.getElementById(firstID).style

  • Javascript variable scope in addEventListener anonymous function 2009-11-22

    When clicking on each div it should alert '1' if div 1 was clicked on or '5' if div 2 was clicked on. I have tried to make this code as easy to as possible because this is needed in a much larger application. <html> <head> <style type=

  • Why does Firefox waits until a javascript function is finished to start another function? 2010-07-28

    we are developing a web application using GWT in the front end. In GWT we make calls to the server by appending javascript code as stated below: public native static void call(int requestId, String url, ICall handler) /*-{ var callback = "callback" +

  • Secret copy to clipboard JavaScript function in Chrome and Firefox? 2010-12-30

    In the console windows of both Chrome and Firefox on Mac I can execute copy("party in your clipboard!"); and the text gets copied to my clipboard. I have searched SO and Google and can't seem to find anything on this. Are these specific to each brows

  • "Evaluate" doesn't work as a javascript function name in Mozilla firefox and google-chrome 2011-01-18

    I wrote a simple html file with just a javascript function. It worked in IE but not in frefox and chrome. The code was: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns

Copyright (C) dskims.com, All Rights Reserved.

processed in 0.171 (s). 11 q(s)