-
Notifications
You must be signed in to change notification settings - Fork 0
/
objects.xml
136 lines (130 loc) · 5.18 KB
/
objects.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
<?xml version="1.0" encoding="UTF-8"?>
<CONTENT TITLE="Objects" ID="objects">
<CONTENT TITLE="What is a native object?" ID="nativeObject">
<P>
A <DFN>native object</DFN> is any object whose semantics are fully defined by
ECMA-262.
</P>
<P>
Some <DFN>native objects</DFN> are <DFN>built-in</DFN>; others, such as <DFN>user-defined</DFN> objects,
may be constructed during the execution of an ECMAScript program.
</P>
<P>
Example:
</P>
<CODE>
// Native built-in objects:
var m = Math, // Built-in Math object.
slice = Array.prototype.slice, // Built-in native method.
o = {}, // Native user-defined object.
f = function(){}, // Native user-defined function.
d = new Date(),
a = [],
e = new Error("My Message.");
</CODE>
See also:
<MOREINFO>
<URL>http://dmitrysoshnikov.com/ecmascript/chapter-7-2-oop-ecmascript-implementation/</URL>
</MOREINFO>
</CONTENT>
<CONTENT TITLE="What is a built-in object?" ID="builtInObject">
<P>
A <DFN>built-in</DFN> object is any object supplied by an ECMAScript
implementation, independent of the host environment, that is present
at the start of the execution of an ECMAScript program.
</P>
<P>
ECMA-262 3rd Edition defines the following <DFN>built-in</DFN> objects:
</P>
<LIST TYPE="DL" ID="builtInsList">
<DT>Objects</DT>
<DD><EM>global</EM>, Math</DD>
<DT>Constructors</DT>
<DD>Object, Function, Array, String, Boolean, Number, Date, RegExp</DD>
<DT>Errors</DT>
<DD>Error, Date, EvalError, RangeError, ReferenceError, SyntaxError, TypeError, URIError</DD>
<DT>Functions</DT>
<DD>eval, parseInt, parseFloat, isNaN, isFinite, decodeURI,
decodeURIComponent, encodeURI, encodeURIComponent</DD>
</LIST>
<P>
ECMA-262 Edition 5 defines also the built-in object <ICODE>JSON</ICODE>.
</P>
<P>
Nonstandard <DFN>built-in</DFN> objects may include <ICODE>RuntimeObject</ICODE>,
<ICODE>String.prototype.link</ICODE>, <ICODE>CollectGarbage</ICODE>, and more.
</P>
</CONTENT>
<CONTENT TITLE="What is a host object?" ID="hostObject" NUMID="2_8">
<P>
A <DFN>host object</DFN> is any object supplied by the host environment to
complete the execution environment of ECMAScript.
</P>
<P>
A <DFN>host object</DFN> is not part of the ECMAScript implementation, but is
exposed to the ECMAScript implementation.
</P>
<P>
A <DFN>host object</DFN> may be implemented as a native ECMAScript object, however
this is not required. For example, Internet Explorer implements many
scriptable DOM objects as ActiveX Objects, often resulting in unexpected errors.
</P>
<P>
Availability and behavior of a host object depends on the host environment.
</P>
<P>
For example, in a browser, <ICODE>XMLHttpRequest</ICODE> might be available, with or
without standard or proprietary features or events. Windows Script Host object model
has the <ICODE>WScript</ICODE> object available.
</P>
<P>
For information on a particular host object, consult the pertinent
documentation available for the implementation(s). For web browsers,
this usually includes the w3c specifications as well as documentation
for that browser.
See also:
</P>
<MOREINFO>
<URL>notes/code-guidelines/#hostObjects</URL>
<URL>http://peter.michaux.ca/articles/feature-detection-state-of-the-art-browser-scripting</URL>
</MOREINFO>
</CONTENT>
<CONTENT TITLE="When should I use eval?" ID="eval" NUMID="4_40">
<P>
The <ICODE>eval</ICODE> function should <EM>only</EM> be used when it is necessary to
evaluate a string supplied or composed at run-time; the string
can be anything from a simple (but unpredictable) expression such
as <ICODE>"12 * 2.54"</ICODE> to a substantial piece of javascript code.
</P>
<P>
When <ICODE>eval( '{"key" : 42}' )</ICODE> is called, <ICODE>{</ICODE> is interpreted as a block of
code instead of an object literal. Hence, the Grouping Operator (parentheses)
is used to force <ICODE>eval</ICODE> to interpret the JSON as an object literal:
<ICODE>eval( '({"key" : 42})' );</ICODE>.
</P>
<MOREINFO>
<URL>http://json.org/</URL>
<URL LINKTEXT="How do I access a property of an object using a string?"
>#propertyAccessAgain</URL>
<URL>notes/square-brackets/</URL>
</MOREINFO>
</CONTENT>
<CONTENT TITLE="How do I access a property of an object using a string?" ID="propertyAccessAgain" NUMID="4_39">
<P>
There are two ways to access properties: dot notation and square bracket
notation. What you are looking for is the square bracket notation in
which the dot, and the identifier to its right, are replaced with a set
of square brackets containing a string. The value of the string matches
the identifier. For example:-
</P>
<CODE>
//dot notation
var bodyElement = document.body;
//square bracket notation, using an expression
var bodyElement = document["bo"+"dy"];
</CODE>
<MOREINFO>
<URL>notes/square-brackets/</URL>
</MOREINFO>
</CONTENT>
</CONTENT>