3. E very object (including host objects) must implement the
e)) and ((Class)) propertie s and the ((Get)), ((Put)),
((Prototyp
t)), ((HasProperty)), ((Dele te)), and ((DefaultValue))
((CanPu
. (Note, however, that the ((D efaultValue)) method may,
methods exception.) The value
for some objects , simply throw a TypeError
Prototype)) property must be either an object or null, and
of the ((
Prototype)) chain must have finite length (that is, starting
every ((
y object, recursively access ing the ((Prototype)) property
from an
entually lead to a null val ue). Whether or not a native
must ev
an have a host object as its ((Prototype)) depends on the
object c
implementation.
The value of the ((Class)) property
is defined by this specification for every
kind of built-i n object. The value of the
((Class)) prop erty of a host object may
be any value , even a value used by
4. E very object (including host objects) must implement the
e)) and ((Class)) propertie s and the ((Get)), ((Put)),
((Prototyp
t)), ((HasProperty)), ((Dele te)), and ((DefaultValue))
((CanPu
. (Note, however, that the ((D efaultValue)) method may,
methods exception.) The value
for some objects , simply throw a TypeError
Prototype)) property must be either an object or null, and
of the ((
Prototype)) chain must have finite length (that is, starting
every ((
from an
must ev
It is a bit “cryptic”
y object, recursively access
entually lead to a null val
ing the ((Prototype)) property
ue). Whether or not a native
an have a host object as its ((Prototype)) depends on the
object c
implementation.
The value of the ((Class)) property
is defined by this specification for every
kind of built-i n object. The value of the
((Class)) prop erty of a host object may
be any value , even a value used by
5. “ECMAScript does not contain proper
classes such as those in C++, Smalltalk, or
Java, but rather, supports constructors
which create objects by executing code
that allocates storage for the objects and
initialises all or part of them by assigning
initial values to their properties.”
ECMAScript Specification
27. function add(a, b) {
return a + b;
}
add(4, 5); // = 9
add(4, 5, 6, 7, 8, 9) // = 39
function add() {
var sum = 0;
for (var i = 0, ii = arguments.length; i < ii; i++) {
sum +=+ arguments[i];
}
return sum;
}
33. function x(a) {
1 return a && x(--a);
}
var x = function (a) {
2 return a && x(--a);
};
setTimeout(function (a) {
3 return a && arguments.callee(--a);
}, 1000);
var x = function y(a) {
4 return a && y(--a);
};
setTimeout(function y(a) {
5 return a && y(--a);
}, 1000);
37. var a = new Object();
var a = {};
var a = {x: 10, y: 15};
var a = {
x: 10,
name: quot;objectquot;,
quot;font-stylequot;: quot;italicquot;,
getHeight: function () {/*...*/},
points: [1, 2, 3],
child: {x: 10, y: 15}
};
40. var mouse = {
1 name: quot;Mikequot;,
voice: function () { alert(quot;Squik!quot;); }
};
var o = new Object();
2 o.name = quot;Mikequot;;
o.voice = function () { alert(quot;Squik!quot;); };
var O = function () {
3 this.name = quot;Mikequot;;
this.voice = function () { alert(quot;Squik!quot;); };
};
var o = new O();
var O = function () {};
4 O.prototype.name = quot;Mikequot;;
O.prototype.voice = function () { alert(quot;Squik!quot;); };
var o = new O();