-
Notifications
You must be signed in to change notification settings - Fork 3
/
prototypical.js
executable file
·41 lines (37 loc) · 1.25 KB
/
prototypical.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
41
console.log("Hello from Prototypical");
function Thing(initialStuff) {
var keys = Object.keys(initialStuff);
for (var i = keys.length - 1; i >= 0; i--) {
this[keys[i]] = initialStuff[keys[i]]
};
}
Thing.prototype.get = function get(key) {
if (this.hasOwnProperty(key)) {
return this[key];
}
else if (this.hasOwnProperty("prototype")) {
var req = new XMLHttpRequest(), val;
req.open("GET", this.prototype, false);
req.send(null);
resp = req.responseText;
try {
val = eval("(" + resp + ")")[key];
} catch (e) { console.error("Unable to parse prototype."); }
return val;
}
}
Thing.prototype.set = function set(key, value) {
this[key] = value;
return this;
}
window.prototypical = {
Thing: Thing,
demo: function () {
var dog = { name: "Sam", breed: "Mutt", prototype: "https://48067914bb3d7935906839bc04226b8b5f55d44b-www.googledrive.com/host/0Bzu4cytkv4B8aXZ0UUpiXzkzclE/boxer.js" };
return new Thing(dog);
},
demo2: function () {
var dog = { name: "Monty", prototype: "https://48067914bb3d7935906839bc04226b8b5f55d44b-www.googledrive.com/host/0Bzu4cytkv4B8aXZ0UUpiXzkzclE/corgi.js" };
return new Thing(dog);
}
}