(info) This AI is still in early stages of development.

Define()

Add, remove or redefine a property on the global scope, overriding any native property of the same name on the global object...

 

Syntax

Define(); // returns an object describing all defines
Define(name); // returns status associated with name
Define(name, value); // add, remove or redefine a global

Parameters

ParameterTypeMandatoryNotesAPI Version
nameString(error)

The name of the define to check / add / remove / replace.

If checking the state of a define, no other parameters are required. See also: Define.stateOf(), Define.has() and Define.hasNative().

If adding, removing or replacing a define, the value parameter must be also specified...

1.0
value

Function

Null

Undefined

Boolean

String

Number

(error)

If specified, the name parameter must also be specified.

A new global const called name will be defined (in the global scope) with a value of value, overriding any property of the same name on the global object:

  • A value of null or undefined will set the value of the global const to undefined, effectively removing the property of the same name on the global object. A define state of Define.REMOVED will be attributed to name.
  • Other values denote the addition or override of of the named property on the global object, with states of Define.ADDED or Define.REPLACED being attributed to their name.

Note that generic objects and arrays are not currently supported. These can be handled in future versions if there are sufficient valid feature requests.

1.0

Return values

Different return values will be generated depending on the parameters supplied:

  • No parameters – an object describing all current defines (keys) and their status (values)
  • Name parameter – a constant describing the state of the define
  • Name and value – define a new value for the named property
ValueTypeNotesAPI Version
<error>Error

An error occurred, most likely:

  • Invalid parameters
  • Trying to define a reserved global property (eg. Math or me)
  • Trying to define something that's already defined
1.0
<obj>Object

If no parameters are specified, an object describing all current defines will be returned.

The enumerable named own properties of the object are the names of things that have been defined, and their values are the statuses of those defines.

Status values can be:

1.0
<state>Constant

If both a name and value were specified, this will be the status of the named property after being defined. Status values can be those listed above.

If only the name parameter was specified, this will be the status of the named property. Status values can be those listed above and, in addition, Define.MISSING which indicates the global property does not exist.

1.0
Availability BETA

Requires:

Contents

Jump to:

Define API

Topics:

  • Define()Add, remove or redefine a property on the global scope, overriding any native property of the same name on the global object...
  • Define API DiagnosticsDiagnostic routines for Define API...
  • Define ScriptsA library of ready made scripts for the Define API...