forked from mach3/js-jquery-class
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjquery.class.js
executable file
·59 lines (59 loc) · 1.56 KB
/
jquery.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
59
/*!
* jQuery.class.js
* Copyirght (c) 2010, matsukaze.
* Lisenced under the MIT license.
*
* @version 1.2.3
* @author mach3
* @requires jQuery
*/
var Class = Class || {};
$.extend( Class, {
/**
* Function to attach class feature to function,
* just like prototype.js's "Class.create()" method.
*
* @param Object superClass Super class object. (optional)
* @return Object Function which has class feature.
* @example
* var MyClass = Class.create();
* MyClass.prototype = { ... };
*/
create: function( superClass ){
var s = superClass || {};
return function(){
var pt, f;
pt = {
superclass:s.prototype,
rebase:function(name){
this[name] = $.extend(true, {}, this[name]);
}
};
f = [ "unbind", "bind", "trigger", "on", "off" ];
$.each(f, function(i, name){
if( $.isFunction($.fn[name])){
pt[name] = function(){ $.fn[name].apply($(this), arguments); };
}
});
$.extend( true, pt, s.prototype, this );
$.extend( true, this, pt );
if( $.isFunction(this.initialize) ){
this.initialize.apply(this, arguments);
}
};
},
/**
* Function to get class defenition directly, wrapper of create().
*
* @param Object def Definition of the class. (required)
* @param Object superClass Super class object. (optional)
* @return Object Class defenition
* @example
* var MyClass = Class.get( { ... }, MySuperClass );
*/
get: function( def, superClass ){
var cls = this.create( superClass );
cls.prototype = def;
return cls;
}
});