-
Notifications
You must be signed in to change notification settings - Fork 0
/
SetDelegate.js
74 lines (62 loc) · 1.62 KB
/
SetDelegate.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/*
function callSetMethods(options) {
return function() {
if (typeof key === 'object') {
options = val;
var attrs = key;
if (typeof options !== 'undefined' && _.isArray(options.order)) {
_.each(options.order, function(prop) {
var methodName = setPrefix(key);
var method = this[methodName];
if (method) {
method.call(this, attrs[prop]);
}
}, this);
}
for (var attr in attrs) {
var methodName = setterMethodName(key);
var method = this[methodName];
}
} else {
var methodName = setPrefix(key);
var method = this[methodName];
if (method) {
method.call(this, val, options);
}
//= ( || Backbone.Model.prototype.set);
return method.call(this, key, val, options);
}
};
}
*/
/*
function SetterDelegate(key, val, options) {
if (typeof key === 'object') {
options = val;
var attrs = key;
for (var attr in attrs) {
var methodName = setterMethodName(key);
var method = this[methodName];
if (_.isFunction(method)) {
}
}
} else {
var methodName = setPrefix(key);
var method = (this[methodName] || Backbone.Model.prototype.set);
return method.call(this, key, val, options);
}
}
*/
function setPrefix(key) {
return "set" + (key[0].toUpperCase() + key.slice(1));
}
function getPrefix(key) {
return "get" + (key[0].toUpperCase() + key.slice(1));
}
function boxAttrs(key, val) {
if (_.isString(key)) {
return ({})[key] = val;
}
return key;
}
var sentinel = {set: function() {}};