-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclass.js
49 lines (43 loc) · 818 Bytes
/
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
/**
* 提供一种统一且简单的方式创建Class
*
* @author qijun.weiqj
*/
define('Class', ['jQuery'], function($) {
/**
* 如:
* var Dialog = new Class({
* init: function() {
* ...
* }
* });
*
* 然后可以这样使用:
*
* var dialog = new Dialog({ width: 400, height: 300 });
*/
var Class = function(parent, o) {
// 省略第一个参数
if (!o) {
o = parent;
parent = null;
}
var klass = function() {
// 可以定义initialize 或 init为构造函数
var init = this.initialize || this.init;
init && init.apply(this, arguments);
},
proto = null;
if (parent) {
proxy.prototype = typeof parent === 'function' ?
parent.prototype : parent;
proto = new proxy();
} else {
proto = {};
}
klass.prototype = $.extend(proto, o);
return klass;
};
var proxy = function() {};
return Class;
});