forked from liammclennan/JavaScript-Koans
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathabout_reflection.js
More file actions
46 lines (41 loc) · 1.59 KB
/
about_reflection.js
File metadata and controls
46 lines (41 loc) · 1.59 KB
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
module("About Reflection (topics/about_reflection.js)");
test("typeof", function() {
equals(typeof({}), __, 'what is the type of an empty object?');
equals(typeof('apple'), __, 'what is the type of a string?');
equals(typeof(-5), __, 'what is the type of -5?');
equals(typeof(false), __, 'what is the type of false?');
});
test("property enumeration", function() {
var keys = [];
var values = [];
var person = {name: 'Amory Blaine', age: 102, unemployed: true};
for(propertyName in person) {
keys.push(propertyName);
values.push(person[propertyName]);
}
ok(keys.equalTo(['__','__','__']), 'what are the property names of the object?');
ok(values.equalTo(['__',__,__]), 'what are the property values of the object?');
});
test("hasOwnProperty", function() {
// hasOwnProperty returns true if the parameter is a property directly on the object,
// but not if it is a property accessible via the prototype chain.
var keys = [];
var fruits = ['apple', 'orange'];
for(propertyName in fruits) {
keys.push(propertyName);
}
ok(keys.equalTo(['__', '__', '__']), 'what are the properties of the array?');
var ownKeys = [];
for(propertyName in fruits) {
if (fruits.hasOwnProperty(propertyName)) {
ownKeys.push(propertyName);
}
}
ok(ownKeys.equalTo(['__', '__']), 'what are the own properties of the array?');
});
test("eval", function() {
// eval executes a string
var result = "";
eval("result = 'apple' + ' ' + 'pie'");
equals(result, __, 'what is the value of result?');
});