-
Notifications
You must be signed in to change notification settings - Fork 3
/
subClassOf.js
34 lines (32 loc) · 1.09 KB
/
subClassOf.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
console.log('subClassOf.js')
Object.prototype.subClassOf=function(x){
if(typeof(x)=='object'){ // prototype is an object in the local scope
var k = Object.getOwnPropertyNames(x)
for(i=0;i<k.length;i++){
if(!this[k[i]]){this[k[i]]=x[k[i]]}
}
console.log(this,'subClassOf',x)
}else{ // assume x is the URL of prototype object and go get it
var that = this
var load = function(url){ // XMLHttpRequest
var r = new XMLHttpRequest();
r.onload=function(){
var x = eval("("+this.responseText+")")
that.subClassOf(x)
};
r.open("GET",url,true);
r.send();
return this
}
load(x)
}
return this
}
// examples:
//
// a={b:9}
// a.subClassOf({c:10})
//
// // slide 34 of http://www.slideshare.net/stefandecker1/stefan-decker-keynote-at-cshals
// HongGeesCar={color:"blue"}
// HongGeesCar.subClassOf("https://0857f9879749e82d493945f8a805968a7c031889-www.googledrive.com/host/0BwwZEXS3GesiTjlHSmlOcEJaeDA/Prototypical/StefansCar.json")