aboutsummaryrefslogtreecommitdiffstats
path: root/extlib/leaflet/src/core/Class.js
blob: 09a9e539343e8f6957dd64d3c7a165527f96e820 (plain)
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
60
61
62
63
64
65
66
/*
 * Class powers the OOP facilities of the library. Thanks to John Resig and Dean Edwards for inspiration!
 */

L.Class = function() {}; 

L.Class.extend = function(/*Object*/ props) /*-> Class*/ {
	
	// extended class with the new prototype
	var NewClass = function() {
		if (!L.Class._prototyping && this.initialize) {
			this.initialize.apply(this, arguments);
		}
	};

	// instantiate class without calling constructor
	L.Class._prototyping = true;
	var proto = new this();
	L.Class._prototyping = false;

	proto.constructor = NewClass;
	NewClass.prototype = proto;
	
	// add superclass access
	proto.superclass = this.prototype;
	
	// add class name
	//proto.className = props;
	
	// mix static properties into the class
	if (props.statics) {
		L.Util.extend(NewClass, props.statics);
		delete props.statics;
	}
	
	// mix includes into the prototype
	if (props.includes) {
		L.Util.extend.apply(null, [proto].concat(props.includes));
		delete props.includes;
	}
	
	// merge options
	if (props.options && proto.options) {
		props.options = L.Util.extend({}, proto.options, props.options);
	}

	// mix given properties into the prototype
	L.Util.extend(proto, props);
	
	// allow inheriting further
	NewClass.extend = arguments.callee;
	
	// method for adding properties to prototype
	NewClass.include = function(props) {
		L.Util.extend(this.prototype, props);
	};
	
	//inherit parent's statics
	for (var i in this) {
		if (this.hasOwnProperty(i) && i != 'prototype') {
			NewClass[i] = this[i];
		}
	}
	
	return NewClass;
};