summaryrefslogtreecommitdiff
path: root/js/dojo-1.6/dojox/drawing/util/oo.xd.js
blob: 21a4460b873aca1d72c134beef77267d57efaacf (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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
/*
	Copyright (c) 2004-2011, The Dojo Foundation All Rights Reserved.
	Available via Academic Free License >= 2.1 OR the modified BSD license.
	see: http://dojotoolkit.org/license for details
*/


dojo._xdResourceLoaded(function(dojo, dijit, dojox){
return {depends: [["provide", "dojox.drawing.util.oo"]],
defineResource: function(dojo, dijit, dojox){if(!dojo._hasResource["dojox.drawing.util.oo"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["dojox.drawing.util.oo"] = true;
dojo.provide("dojox.drawing.util.oo");

// TODO:
// allow a declare without a mixin

dojox.drawing.util.oo = {
	// summary:
	//		Inheritance utilities used in DojoX Drawing
	// description:
	//		Inheritance utilities used in DojoX Drawing.
	//		There were designed in a effort to make Drawing as
	//		fast as possible - especially in a case where thousands
	//		of objects are being loaded. Drawing declare performs
	//		about 3 times faster than Dojo declare and 2 times
	//		faster than Dojox declare. This is not to say Drawing
	//		declare is wthout limitations. It doesn't have the same
	//		syntatic sugar and extensibility of the other two. You
	//		can't inhert methods. It won't work with Dijit. But it
	//		is simple and effective.
	//
	declare: function(){
		// summary:
		//		Creates a constructor Function from a
		//		Function, and collection of methods, and
		//		more Functions that are extended.
		// description:
		//		Similar in look and feel to Dojo declare as
		//		far as order and number of arguments, although
		//		constructed a little closer to prototypical
		//		inheritance. All arguments passed into the
		//		constructor are passed into all sub constructors.
		// arguments:
		//		Function, [Object|Function....]
		//			The first argument is always the base
		//			constructor. The last argument is always
		//			an object of methods (or empty object) to
		//			be mixed in (in the future would like to
		//			make that object optional). Remaining
		//			arguments are other constructors mixed in
		//			using extend() (See below).
		// example:
		//		|	MyFunction = dojox.drawing.util.oo.declare(
		//		|		MyOtherFunction,
		//		|		YetAnotherFunction,
		//		|		function(options){
		//		|			// This is my constructor. It will fire last.
		//		|			// The other constructors will fire before this.
		//		|		},
		//		|		{
		//		|			customType:"equation", // mixed in property
		//		|			doThing: function(){   // mixed in method
		//		|
		//		|			}
		//		|		}
		//		|	);
		//		|
		//		|	var f = new MyFunction();
		//
		var f, o, ext=0, a = arguments;
				
		if(a.length<2){ console.error("gfx.oo.declare; not enough arguments")}
		if(a.length==2){
			f = a[0]; o = a[1];
		}else{
			a = Array.prototype.slice.call(arguments);
			o = a.pop();
			f = a.pop();
			ext = 1;
		}
		for(var n in o){
			f.prototype[n] = o[n];
		}
		if(ext){
			a.unshift(f);
			f = this.extend.apply(this, a);
		}
		return f; // Function
	},
	extend: function(){
		// summary:
		//		Extends constructors to inherit from other
		//		constructors .
		// description:
		//		Typically not used by itself - it's used as
		//		part of declare(). Could be used by itself
		//		however, to mix together two or more
		//		constructors.
		// arguments:
		//		Function, [ Function...]
		//			Any number of arguments, all must be
		//			function constructors. The first is
		//			considered the base object and its
		//			constructor will fire first.
		// example:
		//		|	var A = function(){};
		//		|	var B = function(){};
		//		|	var C = function(){};
		// 		|	var D = dojox.drawing.util.oo.extend(A, B, C);
		//		|	var e = new D();
		//
		var a = arguments, sub = a[0];
		if(a.length<2){ console.error("gfx.oo.extend; not enough arguments")}
		var f = function (){
			for(var i=1;i<a.length;i++){
				a[i].prototype.constructor.apply(this, arguments);
			}
			// sub should fire last
			sub.prototype.constructor.apply(this, arguments);
			
		}
		for(var i=1;i<a.length;i++){
			for(var n in a[i].prototype){
				f.prototype[n] = a[i].prototype[n];
			}
		}
			
		for(n in sub.prototype){
			f.prototype[n] = sub.prototype[n];
		}
		return f; // Function
	}
};

}

}};});