forked from joesonw/node-php-serialization
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathClass.js
58 lines (57 loc) · 1.77 KB
/
Class.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
(function(window, exports) {
exports.Class=Class;
function Class(name) {
this.__name__=name;
this.__attr__={};
}
Class.prototype.__has__=function(k) {
return (k in this.__attr__);
};
Class.prototype.__addAttr__=function(name,kType,val,type,scope,getter,setter) {
var _getter=getter;
var _setter=setter;
if (scope==undefined) {
scope="public";
}
if (_getter==undefined) {
_getter=function() {
return val;
}
}
if (_setter==undefined) {
_setter=function(v) {
val=v;
}
}
this.__attr__[name]={val:val,type:type,scope:scope,get:_getter,set:_setter,kType:kType}
Object.defineProperty(this,name,{
get:function() {
return this.__attr__[name].get();
},
set:function(v) {
this.__attr__[name].set(v);
}
});
};
Class.prototype.__typeOf__=function(name) {
return this.__attr__[name].type;
};
Class.prototype.__keyTypeOf__=function(name) {
return this.__attr__[name].kType;
};
Class.prototype.__scopeOf__=function(name) {
return this.__attr__[name].scope;
};
Class.prototype.toString=function() {
var result=this.__name__+":Class";
for (k in this.__attr__) {
var attr=this.__attr__[k]
var val=attr.constructor;
result+=k+"-";
result+=attr.scope+":";
result+=val.__type__.toString();
result+=val.get().toString();
}
return result;
}
})((typeof window === 'undefined') ? global : window, (typeof window === 'undefined') ? exports : (window.Class = {}));