| 
									
										
										
										
											2014-11-18 19:51:41 +03:00
										 |  |  | /********************************************************************** | 
					
						
							|  |  |  | *  | 
					
						
							|  |  |  | * | 
					
						
							|  |  |  | * | 
					
						
							|  |  |  | **********************************************************************/ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | define(function(require){ var module = {} | 
					
						
							|  |  |  | console.log('>>> objects') | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | //var DEBUG = DEBUG != null ? DEBUG : true
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*********************************************************************/ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-12-07 04:56:19 +03:00
										 |  |  | // XXX BUG: if the constructor is called from it's instance this will 
 | 
					
						
							|  |  |  | // 		return the instance and not a new object...
 | 
					
						
							| 
									
										
										
										
											2014-11-18 19:51:41 +03:00
										 |  |  | var makeConstructor = | 
					
						
							|  |  |  | module.makeConstructor = | 
					
						
							|  |  |  | function makeConstructor(name, a, b){ | 
					
						
							|  |  |  | 	var proto = b == null ? a : b | 
					
						
							|  |  |  | 	var cls_proto = b == null ? b : a | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-11-18 20:20:35 +03:00
										 |  |  | 	var _constructor = function Constructor(){ | 
					
						
							| 
									
										
										
										
											2015-12-08 05:24:06 +03:00
										 |  |  | 		/* | 
					
						
							| 
									
										
										
										
											2014-11-18 19:51:41 +03:00
										 |  |  | 		// in case this is called as a function (without new)...
 | 
					
						
							|  |  |  | 		if(this.constructor !== _constructor){ | 
					
						
							| 
									
										
										
										
											2015-12-08 05:24:06 +03:00
										 |  |  | 			// NOTE: the following does the job of the 'new' operator but
 | 
					
						
							|  |  |  | 			// 		with one advantage, we can now pass arbitrary args 
 | 
					
						
							| 
									
										
										
										
											2014-11-18 20:20:35 +03:00
										 |  |  | 			// 		in...
 | 
					
						
							|  |  |  | 			// 		This is equivalent to:
 | 
					
						
							|  |  |  | 			//			return new _constructor(json)
 | 
					
						
							|  |  |  | 			var obj = {} | 
					
						
							|  |  |  | 			obj.__proto__ = _constructor.prototype | 
					
						
							| 
									
										
										
										
											2014-11-30 03:45:38 +03:00
										 |  |  | 			// XXX for some reason this does not resolve from .__proto__
 | 
					
						
							| 
									
										
										
										
											2014-11-18 20:20:35 +03:00
										 |  |  | 			obj.constructor = _constructor | 
					
						
							| 
									
										
										
										
											2014-12-08 19:11:53 +03:00
										 |  |  | 			//obj.__proto__.constructor = _constructor
 | 
					
						
							| 
									
										
										
										
											2014-11-18 20:20:35 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 			var obj = this | 
					
						
							| 
									
										
										
										
											2014-11-18 19:51:41 +03:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2015-12-08 05:24:06 +03:00
										 |  |  | 		*/ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		// NOTE: the following does the job of the 'new' operator but
 | 
					
						
							|  |  |  | 		// 		with one advantage, we can now pass arbitrary args 
 | 
					
						
							|  |  |  | 		// 		in...
 | 
					
						
							|  |  |  | 		// 		This is equivalent to:
 | 
					
						
							|  |  |  | 		//			return new _constructor(json)
 | 
					
						
							|  |  |  | 		var obj = {} | 
					
						
							|  |  |  | 		obj.__proto__ = _constructor.prototype | 
					
						
							|  |  |  | 		// XXX for some reason this does not resolve from .__proto__
 | 
					
						
							|  |  |  | 		obj.constructor = _constructor | 
					
						
							|  |  |  | 		//obj.__proto__.constructor = _constructor
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-11-18 19:51:41 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		// load initial state...
 | 
					
						
							| 
									
										
										
										
											2014-11-18 20:20:35 +03:00
										 |  |  | 		if(obj.__init__ != null){ | 
					
						
							|  |  |  | 			obj.__init__.apply(obj, arguments) | 
					
						
							| 
									
										
										
										
											2014-11-18 19:51:41 +03:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-11-18 20:20:35 +03:00
										 |  |  | 		return obj | 
					
						
							| 
									
										
										
										
											2014-11-18 19:51:41 +03:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-11-18 20:20:35 +03:00
										 |  |  | 	// this is here to make Chrome output more user friendly...
 | 
					
						
							| 
									
										
										
										
											2014-11-24 17:37:50 +03:00
										 |  |  | 	// skip for IE...
 | 
					
						
							| 
									
										
										
										
											2015-10-01 12:11:03 +03:00
										 |  |  | 	if(_constructor.name == 'Constructor'){ | 
					
						
							| 
									
										
										
										
											2014-11-24 17:37:50 +03:00
										 |  |  | 			// skip for chrome app...
 | 
					
						
							| 
									
										
										
										
											2015-10-01 12:11:03 +03:00
										 |  |  | 			//&& !(window.chrome && chrome.runtime && chrome.runtime.id)){
 | 
					
						
							| 
									
										
										
										
											2014-11-18 20:20:35 +03:00
										 |  |  | 		eval('_constructor = '+ _constructor | 
					
						
							|  |  |  | 				.toString() | 
					
						
							|  |  |  | 				.replace(/Constructor/g, name)) | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-11-18 19:51:41 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	_constructor.__proto__ = cls_proto | 
					
						
							|  |  |  | 	_constructor.prototype = proto | 
					
						
							|  |  |  | 	_constructor.prototype.constructor = _constructor | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return _constructor | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-31 20:13:29 +03:00
										 |  |  | // super equivalent...
 | 
					
						
							| 
									
										
										
										
											2015-11-15 01:25:04 +03:00
										 |  |  | //
 | 
					
						
							|  |  |  | // Example:
 | 
					
						
							|  |  |  | // 	superMethod(<class>, <method-name>).call(this, ...)
 | 
					
						
							|  |  |  | // 		-> <result>
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | // This will return a next method in inheritance chain after <class> by
 | 
					
						
							|  |  |  | // its name (<method-name>).
 | 
					
						
							|  |  |  | // In the normal use-case <class> is the current class and <method-name>
 | 
					
						
							|  |  |  | // is the name of the current method.
 | 
					
						
							| 
									
										
										
										
											2015-09-20 21:54:28 +03:00
										 |  |  | var superMethod = | 
					
						
							|  |  |  | module.superMethod = | 
					
						
							|  |  |  | function superMethod(cls, meth){ | 
					
						
							|  |  |  | 	return cls.prototype.__proto__[meth] | 
					
						
							| 
									
										
										
										
											2015-08-31 20:13:29 +03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-11-18 19:51:41 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | /********************************************************************** | 
					
						
							|  |  |  | * vim:set ts=4 sw=4 :                                                */ | 
					
						
							|  |  |  | return module }) |