mirror of
				https://github.com/flynx/object.js.git
				synced 2025-10-30 19:10:11 +00:00 
			
		
		
		
	cleanup...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
		
							parent
							
								
									ead4ed4868
								
							
						
					
					
						commit
						21ea5d8b37
					
				
							
								
								
									
										32
									
								
								README.md
									
									
									
									
									
								
							
							
						
						
									
										32
									
								
								README.md
									
									
									
									
									
								
							| @ -58,9 +58,9 @@ var L = object.Constructor('L', Array, { | ||||
| ``` | ||||
| 
 | ||||
| - Clear separation of constructor and `.prototype` data: | ||||
| 	- First block (optional) is merged with constructor | ||||
| 	- Second block is the `.prototype` | ||||
| - no direct way to define "private"  | ||||
| 	- First block (optional) is merged with `L`, | ||||
| 	- Second block _is_ the `.prototype`, | ||||
| - no direct way to do "private" definitions. | ||||
| 
 | ||||
| </td> | ||||
| <td> | ||||
| @ -87,7 +87,8 @@ class L extends Array { | ||||
| 	} | ||||
| } | ||||
| ``` | ||||
| - `static` and instance definitions are mixed within the body, | ||||
| - pretty but misleading syntax, | ||||
| - `static` and instance definitions are not ordered, | ||||
| - `.attr` is copied to every instance | ||||
| 
 | ||||
| </td> | ||||
| @ -148,7 +149,7 @@ we simply need to _link_ the prototypes of two constructors via `.__proto__`, | ||||
| `Object.create(..)` or other means. | ||||
| 
 | ||||
| ```javascript | ||||
| var B = object.Constructor('B', { __extends__: A }) | ||||
| var B = object.Constructor('B', A, {}) | ||||
| 
 | ||||
| var C = object.Constructor('C', B, {}) | ||||
| ``` | ||||
| @ -183,10 +184,7 @@ var Base = object.Constructor('Base', { | ||||
| 	}, | ||||
| }) | ||||
| 
 | ||||
| var Item = object.Constructor('Item', { | ||||
| 	// inherit from Base... | ||||
| 	__extends__: Base, | ||||
| 
 | ||||
| var Item = object.Constructor('Item', Base, { | ||||
| 	__init__: function(){ | ||||
| 		// call the "super" method... | ||||
| 		object.parentCall(this.prototype.__init__, this) | ||||
| @ -322,27 +320,20 @@ var C = object.Constructor('C', | ||||
| 
 | ||||
| And the same thing while extending... | ||||
| ```javascript | ||||
| var D = object.Constructor('D', | ||||
| var D = object.Constructor('D', C, | ||||
| 	// this will get mixed into C(..)... | ||||
| 	{ | ||||
| 		__extends__: C, | ||||
| 
 | ||||
| 		// ... | ||||
| 	}, { | ||||
| 		// ... | ||||
| 	}) | ||||
| ``` | ||||
| 
 | ||||
| Note that `.__extends__` can be written in either block, this is done  | ||||
| for convenience and to keep it as close as possible to the definition top. | ||||
| 
 | ||||
| 
 | ||||
| ### Inheriting from native constructor objects | ||||
| 
 | ||||
| ```javascript | ||||
| var myArray = object.Constructor('myArray', { | ||||
| 	__extends__: Array, | ||||
| 
 | ||||
| var myArray = object.Constructor('myArray', Array, { | ||||
| 	// ... | ||||
| }) | ||||
| ``` | ||||
| @ -361,9 +352,7 @@ Extending `.constructor(..)` is not necessary in most cases as | ||||
| replacement. | ||||
| 
 | ||||
| ```javascript | ||||
| var myArray = object.Constructor('myArray', { | ||||
| 	__extends__: Array, | ||||
| 
 | ||||
| var myArray = object.Constructor('myArray', Array, { | ||||
| 	__new__: function(context, ...args){ | ||||
| 		var obj = Reflect.construct(myArray.__proto__, args, myArray) | ||||
| 
 | ||||
| @ -454,6 +443,7 @@ Define an object constructor | ||||
| Constructor(<name>) | ||||
| Constructor(<name>, <prototype>) | ||||
| Constructor(<name>, <parent-constructor>, <prototype>) | ||||
| Constructor(<name>, <parent-constructor>, <constructor-mixin>, <prototype>) | ||||
| Constructor(<name>, <constructor-mixin>, <prototype>) | ||||
| 	-> <constructor> | ||||
| ``` | ||||
|  | ||||
							
								
								
									
										21
									
								
								object.js
									
									
									
									
									
								
							
							
						
						
									
										21
									
								
								object.js
									
									
									
									
									
								
							| @ -427,16 +427,6 @@ function(context, constructor, ...args){ | ||||
| // 
 | ||||
| //
 | ||||
| // 
 | ||||
| // Special attributes:
 | ||||
| // 	.__extends__
 | ||||
| // 		Shorthand to define define the prototype constructor.
 | ||||
| //			Constructor('X', {__extends__: Y})
 | ||||
| //		is the same as:
 | ||||
| //			Constructor('X', Y, {})
 | ||||
| // 		This can be defined on either the prototype or the constructor
 | ||||
| // 		mixin but not on both.
 | ||||
| //
 | ||||
| //
 | ||||
| // Special methods (constructor):
 | ||||
| //
 | ||||
| //  Handle uninitialized instance construction
 | ||||
| @ -474,7 +464,7 @@ function(context, constructor, ...args){ | ||||
| // 		// NOTE: new is optional...
 | ||||
| // 		var A = new Constructor('A')
 | ||||
| //
 | ||||
| // 		var B = Constructor('B', { __extends__: A })
 | ||||
| // 		var B = Constructor('B', A, {})
 | ||||
| //
 | ||||
| // 		var C = Constructor('C', B, {})
 | ||||
| //
 | ||||
| @ -540,13 +530,12 @@ function Constructor(name, a, b, c){ | ||||
| 
 | ||||
| 	// handle: 
 | ||||
| 	// 	Constructor(name, constructor, ..)
 | ||||
| 	if(constructor_proto){ | ||||
| 		proto.__proto__ === Object.prototype | ||||
| 	constructor_proto | ||||
| 		&& proto.__proto__ === Object.prototype | ||||
| 		&& (proto.__proto__ = constructor_proto.prototype) | ||||
| 
 | ||||
| 	// handle: 
 | ||||
| 	// 	Constructor(name, ..)
 | ||||
| 	} else { | ||||
| 	// handle: .__extends__
 | ||||
| 	if(!constructor_proto){ | ||||
| 		// handle .__extends__
 | ||||
| 		a = Object.hasOwnProperty.call(proto, '__extends__') | ||||
| 				&& proto.__extends__ | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user