Please note, this is a STATIC archive of website developer.mozilla.org from 03 Nov 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

Components.utils.getGlobalForObject

This method is used to determine the global object with which an object is associated. This is the global object in place at the time the object was created, which is to say the global object used when executing the script that created the object.

Syntax

var global = Components.utils.getGlobalForObject(obj);

Parameters

obj
an object whose corresponding global object is to be retrieved; non-optional, must be object-valued

Example

var obj = {};
function foo() { }
var global = this;

var g1 = Components.utils.getGlobalForObject(foo);
var g2 = Components.utils.getGlobalForObject(obj);
// g1 === global, g2 === global, g1 === g2

// In a script in another window
var global2 = this;
function bar() { }
var obj2 = {};

// Then, assuming bar refers to the function defined in that other window:
var o1 = Components.utils.getGlobalForObject(bar);
var o2 = Components.utils.getGlobalForObject(obj2);
// o1 === global2, o2 === global2

Document Tags and Contributors

 Contributors to this page: teoli, trevorh, Waldo
 Last updated by: trevorh,