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
|
function hasOwnProp(o, p) {
return Object.prototype.hasOwnProperty.call(o, p);
}
function testHasProp() {
var C = Object.create(null);
C.protox = 0;
var B = Object.create(C);
var objs = [];
for (var i = 0; i < 50; i++) {
var A = Object.create(B);
A["x" + i] = 0;
A.ownx = 3;
objs.push(A);
}
for (var i = 0; i < 10; i++) {
for (var j = 0; j < objs.length; j++) {
var obj = objs[j];
assertEq(hasOwnProp(obj, "protox"), false);
assertEq("protox" in obj, true);
assertEq(obj.protox, 0);
assertEq(hasOwnProp(obj, "ownx"), true);
assertEq("ownx" in obj, true);
assertEq(obj.ownx, 3);
assertEq("missing" in obj, false);
assertEq(hasOwnProp(obj, "missing"), false);
assertEq(obj.missing, undefined);
}
}
}
testHasProp();
|