Components.utils.getGlobalForObject

Nos bénévoles n'ont pas encore traduit cet article en Français. Aidez-nous à réaliser cette tâche !

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

Étiquettes et contributeurs liés au document

Contributeurs ayant participé à cette page : trevorh, Waldo
Dernière mise à jour par : trevorh,