-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathminimal-test.js
40 lines (32 loc) · 891 Bytes
/
minimal-test.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
35
36
37
38
39
40
/*eslint no-console: ["error", { allow: ["log"] }] */
(function() {
"use strict";
// Declare Io POC
function Io() {
this.tree = [];
}
Io.prototype.up = function() {
var a = Object.create(this);
this.tree.push(a);
a.tree = [];
return a;
};
// Create version tree
var root = new Io();
// Set values in root
root.key = "value";
root.key2 = { objects: "work" };
// Make a new branch using up()
var branch = root.up();
// Prototypical inheritance
console.log(Object.getPrototypeOf(branch) === root);
console.log(root.isPrototypeOf(branch));
// Set value in branch
branch.key = "value2";
// Version tree can be traversed from root
console.log(root.tree[0] === branch);
// Properties are inherited from parent
console.log(branch.key2 === root.key2);
// Branches override values
console.log(branch.key !== root.key);
})();