-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathutil.js
More file actions
59 lines (58 loc) · 1.33 KB
/
util.js
File metadata and controls
59 lines (58 loc) · 1.33 KB
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
var overload=require("./overload")
, Watchable = overload.Watchable
, RePrototype = overload.RePrototype
exports.ReadOnly=ReadOnly=function(obj,mask,filter) {
var $this=Watchable(function(args){
var v=mask
&& args.property in mask
? mask[args.property]
: obj[args.property];
if(typeof(v)=="function") {
return function(){return v.apply(obj,arguments)}
}
return v;
},filter?function(ArgInfo){
var property = ArgInfo.property
if(filter(property)) {
obj[property] = ArgInfo.value
}
}:undefined);
//only objects have prototypes
if(obj instanceof Object) {
RePrototype($this,Object.getPrototypeOf(obj))
}
return $this;
}
var noop=function(){}
ReadOnly.ArrayMask={
pop:function(){return this[this.length-1];}
,push:function(){return this.length}
,reverse:noop
,shift:function(){return this[0];}
,sort:noop
,splice:function(){return [];}
,unshift:function(){return this.length}
}
ReadOnly.ArrayFilter = function(property) {
return typeof property !== "number"
}
ReadOnly.DateMask={
setDate:noop
,setFullYear:noop
,setHours:noop
,setMilliseconds:noop
,setMinutes:noop
,setMonth:noop
,setSeconds:noop
,setTime:noop
,setUTCDate:noop
,setUTCFullYear:noop
,setUTCHours:noop
,setUTCMilliseconds:noop
,setUTCMinutes:noop
,setUTCMonth:noop
,setUTCSeconds:noop
,setYear:noop
}
ReadOnly.StringMask={}
delete noop;