Report abuse

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
/*
values for exposes:
true: all set/getFoo are converted to setters/getters
false: do nothing
string: "foo" => only convert get/setFoo to setters getters if present
array of strings: like above, but for each string
*/

Class.Mutators.Exposes = function(self, attributes){
    if (attributes !== true) attributes = $splat(attributes);
    for (method in self) {
        var match = method.match(/^(get|set)([A-Z])(\w*)$/);
        if (match) {
            var prop = match[2].toLowerCase() + match[3];
            if (attributes !== true && !attributes.contains(prop)) continue;
            self[(match[1] == 'get') ? '__defineGetter__' : '__defineSetter__'](prop, self[method]);
        }
    }
};