Table of contents
- 1.1. Syntax
- 1.2. Parameters
- 1.3. Return value
- 1.4. Example
- 2. See also
This method creates a new JavaScript object in the scope of the specified object's compartment.
Syntax
var newObject = Components.utils.createObjectIn(obj);
Parameters
obj- An object indicating the compartment in which the new object should be created; the new object will be created in the scope of this object's compartment.
Return value
A new object in the specified scope.
Example
To create a new object in the scope of a specified DOM window, you can simply do:
function genPropDesc(value) {
return {
enumerable: true, configurable: true, writable: true, value: value
};
}
var myObject = Components.utils.createObjectIn(myWindow);
var propList = {
name: genPropDesc("name"),
date: genPropDesc("date"),
id: genPropDesc("id"),
func: genPropDesc(function() { alert("Called func!"); })
};
Object.defineProperties(myObject, propList);
Components.utils.makeObjectPropsNormal(myObject);
This sets up the new object in the scope of the object myWindow, then adds properties by calling Object.defineProperties(), then normalizes them by calling Components.utils.makeObjectPropsNormal().


Mozilla Developer Network