|
1 | 1 | #Node-Overload |
2 | 2 |
|
| 3 | +##install |
| 4 | + |
| 5 | +####If you have npm |
| 6 | +1. npm install overload |
| 7 | + |
| 8 | +####Raw |
| 9 | +1. run __make__ |
| 10 | +2. files are in lib directory |
| 11 | + |
3 | 12 | ##exports |
4 | 13 |
|
| 14 | +####overload.node |
| 15 | + |
5 | 16 | * Watchable(onGet,onSet,onForeach,onQuery,onDelete) |
6 | 17 |
|
7 | 18 | Callback's can use the __this__ object in order to act normally without reinvoking themselves. |
8 | 19 |
|
9 | | -* Value onGet(String propertyName, Value value, hadAlready) |
| 20 | +* * Value onGet(ArgInfo) - property |
10 | 21 |
|
11 | 22 | Returns the value at a specific index |
12 | | -* Value onSet(String propertyName, Value oldValue, Value value, hadAlready) |
| 23 | +* * Value onSet(ArgInfo) - property, value |
13 | 24 |
|
14 | 25 | Returns the value to save at a specific index |
15 | | -* Array onForeach() |
| 26 | +* * Array onForeach(ArgInfo) |
16 | 27 |
|
17 | 28 | Returns an array containing all the index keys for this object |
18 | | -* Boolean onQuery(String propertyName, Value value, hadAlready) |
| 29 | +* * Boolean onQuery(ArgInfo) - property |
19 | 30 |
|
20 | 31 | Returns whether the object has a specific index |
21 | | -* Boolean onDelete(String propertyName, Value value, hadAlready) |
| 32 | +* * Boolean onDelete(ArgInfo) - property |
22 | 33 |
|
23 | 34 | Returns whether the object was successful in deleting a specific index |
24 | 35 |
|
| 36 | +* * ArgInfo Values - holder thisObject property? value? |
| 37 | + |
| 38 | +* RePrototype(obj,proto) |
| 39 | + |
| 40 | + Set obj's prototype to proto |
| 41 | + |
| 42 | +####proxy.js |
| 43 | + |
| 44 | +Partial implementation of ES Harmony Proxy API. |
| 45 | + |
| 46 | +####utils.js |
| 47 | + |
| 48 | +* ReadOnly(obj,mask) |
| 49 | + |
| 50 | + Prevent an object from being modified w/ a setter. Methods on this object may still modify the object. |
| 51 | + |
| 52 | +* * mask - list of properties to intercept properties (useful to replace methods you dont want to modify the object) |
| 53 | + |
| 54 | +* * ReadOnly.ArrayMask |
| 55 | + |
| 56 | +* * ReadOnly.DateMask |
25 | 57 |
|
26 | 58 | ##example |
27 | 59 |
|
28 | 60 | ####Code |
29 | | - |
30 | | - //print out any property gets that use the . operator |
| 61 | + var proxied={hello:""} |
31 | 62 | var debug = Watchable( |
32 | | - function(propertyName,value,hadAlready){ |
| 63 | + //GETTER |
| 64 | + function(ArgInfo){ |
33 | 65 | //check the type of the object contained by value |
34 | 66 | //undefined if no value, or number if using []'s with a number |
35 | | - if(typeof value === "string") { |
36 | | - sys.puts(propertyName); |
37 | | - } |
38 | | - return value; |
| 67 | + var property=ArgInfo.property |
| 68 | + sys.puts("GET:"+JSON.stringify(property),"VALUE:"+String(proxied[property])); |
| 69 | + return proxied[property]; |
39 | 70 | } |
40 | | - function(propertyName,oldValue,value,hadAlready) { |
41 | | - return value; |
| 71 | + //SETTER |
| 72 | + , function(ArgInfo) { |
| 73 | + var property=ArgInfo.property |
| 74 | + var value=ArgInfo.value |
| 75 | + sys.puts("GET:"+JSON.stringify(property),"VALUE:"+String(proxied[property]),"NEW VALUE:"+String()); |
| 76 | + pro |
| 77 | + return ArgInfo.value; |
42 | 78 | } |
43 | 79 | ) |
44 | 80 | debug.hello |
45 | | - debug[" world!"] |
| 81 | + debug[" world!"]=true |
46 | 82 |
|
47 | 83 | ####Output |
48 | 84 |
|
49 | | - hello |
50 | | - world! |
| 85 | + GET:"hello" |
| 86 | + VALUE: |
| 87 | + SET:" world!" |
| 88 | + VALUE:undefined |
| 89 | + VALUE:true |
51 | 90 |
|
52 | 91 | ##uses |
53 | 92 |
|
| 93 | +* Watchable |
54 | 94 | 1. Debugging - Show what is being accessed / set |
55 | 95 | 2. False natives - refuse to allow properties to be set / got beyond a specified few |
56 | 96 | 3. Dynamic programming - Fib[3] could compute Fib[1] and Fib[2] |
57 | | -4. Index based getters / setters - Fib[0] cannot have a getter set normally because it is a number not string based index (all non-number non-undefined values become string based). |
| 97 | +4. Index based getters / setters - Fib[0] cannot have a getter set normally because it is a number not string based index (all non-number non-undefined values become string based). |
| 98 | + |
| 99 | +* RePrototype |
| 100 | +1. Making Watchables follow the instanceof operator |
| 101 | +2. Making extensions of Objects follow the instanceof operator |
| 102 | + |
| 103 | +* ReadOnly |
| 104 | +1. Making arrays that cant be messed with |
0 commit comments