Skip to content

Commit d8a41a8

Browse files
author
Bradley Meck
committed
test
1 parent 63b9559 commit d8a41a8

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed

test/proxy.js

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
var Watchable = require("../lib/overload").Watchable
2+
, sys = require("sys")
3+
var proxied={hello:""}
4+
var debug = Watchable(
5+
//GETTER
6+
function(ArgInfo){
7+
//check the type of the object contained by value
8+
//undefined if no value, or number if using []'s with a number
9+
var property=ArgInfo.property
10+
sys.puts("GET:"+JSON.stringify(property),"VALUE:"+String(proxied[property]));
11+
return proxied[property];
12+
}
13+
//SETTER
14+
, function(ArgInfo) {
15+
var property=ArgInfo.property
16+
var value=ArgInfo.value
17+
sys.puts("GET:"+JSON.stringify(property),"VALUE:"+String(proxied[property]),"NEW VALUE:"+String(value));
18+
return ArgInfo.value;
19+
}
20+
)
21+
debug.hello
22+
debug[" world!"]=true
23+
24+
var x={A:1,B:2},y={B:"B",C:"C"}
25+
var proto_chain = [x,y];
26+
var multi_proto = Watchable(
27+
//GETTER
28+
function(ArgInfo){
29+
//check the type of the object contained by value
30+
//undefined if no value, or number if using []'s with a number
31+
var property=ArgInfo.property
32+
for(var i=proto_chain.length;i>=0;i--) {
33+
var proto = proto_chain[i]
34+
if(property in proto) {
35+
return proto[property]
36+
}
37+
}
38+
return undefined
39+
}
40+
//SETTER
41+
, function(ArgInfo) {
42+
//DONT SET THE CHAINS VALUES!
43+
}
44+
, function(ArgInfo) {
45+
46+
}
47+
, function(ArgInfo) {
48+
var property=ArgInfo.property
49+
return proto_chain.some(function(item){return property in item})
50+
}
51+
)
52+
53+
var z = function(){};
54+
z.prototype = multi_proto
55+
z = new z;
56+
console.log(z.A);
57+
console.log(z.B);
58+
console.log(z.C);

0 commit comments

Comments
 (0)