-
Notifications
You must be signed in to change notification settings - Fork 5
/
examples.js
34 lines (31 loc) · 916 Bytes
/
examples.js
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
var StringMap = require("./stringmap");
var sm1 = new StringMap();
sm1.set("greeting", "yoyoma");
sm1.set("check", true);
sm1.set("__proto__", -1);
console.log(sm1.has("greeting")); // true
console.log(sm1.get("__proto__")); // -1
sm1.remove("greeting");
console.log(sm1.keys()); // [ 'check', '__proto__' ]
console.log(sm1.values()); // [ true, -1 ]
console.log(sm1.items()); // [ [ 'check', true ], [ '__proto__', -1 ] ]
console.log(sm1.toString()); // {"check":true,"__proto__":-1}
var sm2 = new StringMap({
one: 1,
two: 2,
});
console.log(sm2.map(function(value, key) {
return value * value;
})); // [ 1, 4 ]
sm2.forEach(function(value, key) {
// ...
});
console.log(sm2.isEmpty()); // false
console.log(sm2.size()); // 2
var sm3 = sm1.clone();
sm3.merge(sm2);
sm3.setMany({
a: {},
b: [],
});
console.log(sm3.toString()); // {"check":true,"one":1,"two":2,"a":{},"b":[],"__proto__":-1}