2 * Class powers the OOP facilities of the library. Thanks to John Resig and Dean Edwards for inspiration!
5 L
.Class = function() {};
7 L
.Class
.extend = function(/*Object*/ props
) /*-> Class*/ {
9 // extended class with the new prototype
10 var NewClass = function() {
11 if (!L
.Class
._prototyping
&& this.initialize
) {
12 this.initialize
.apply(this, arguments
);
16 // instantiate class without calling constructor
17 L
.Class
._prototyping
= true;
18 var proto
= new this();
19 L
.Class
._prototyping
= false;
21 proto
.constructor = NewClass
;
22 NewClass
.prototype = proto
;
24 // add superclass access
25 proto
.superclass
= this.prototype;
28 //proto.className = props;
30 // mix static properties into the class
32 L
.Util
.extend(NewClass
, props
.statics
);
36 // mix includes into the prototype
38 L
.Util
.extend
.apply(null, [proto
].concat(props
.includes
));
39 delete props
.includes
;
43 if (props
.options
&& proto
.options
) {
44 props
.options
= L
.Util
.extend({}, proto
.options
, props
.options
);
47 // mix given properties into the prototype
48 L
.Util
.extend(proto
, props
);
50 // allow inheriting further
51 NewClass
.extend
= arguments
.callee
;
53 // method for adding properties to prototype
54 NewClass
.include = function(props
) {
55 L
.Util
.extend(this.prototype, props
);
58 //inherit parent's statics
60 if (this.hasOwnProperty(i
) && i
!= 'prototype') {
61 NewClass
[i
] = this[i
];