mirror of
https://github.com/flynx/object.js.git
synced 2025-10-30 02:50:10 +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:
|
- Clear separation of constructor and `.prototype` data:
|
||||||
- First block (optional) is merged with constructor
|
- First block (optional) is merged with `L`,
|
||||||
- Second block is the `.prototype`
|
- Second block _is_ the `.prototype`,
|
||||||
- no direct way to define "private"
|
- no direct way to do "private" definitions.
|
||||||
|
|
||||||
</td>
|
</td>
|
||||||
<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
|
- `.attr` is copied to every instance
|
||||||
|
|
||||||
</td>
|
</td>
|
||||||
@ -148,7 +149,7 @@ we simply need to _link_ the prototypes of two constructors via `.__proto__`,
|
|||||||
`Object.create(..)` or other means.
|
`Object.create(..)` or other means.
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
var B = object.Constructor('B', { __extends__: A })
|
var B = object.Constructor('B', A, {})
|
||||||
|
|
||||||
var C = object.Constructor('C', B, {})
|
var C = object.Constructor('C', B, {})
|
||||||
```
|
```
|
||||||
@ -183,10 +184,7 @@ var Base = object.Constructor('Base', {
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
var Item = object.Constructor('Item', {
|
var Item = object.Constructor('Item', Base, {
|
||||||
// inherit from Base...
|
|
||||||
__extends__: Base,
|
|
||||||
|
|
||||||
__init__: function(){
|
__init__: function(){
|
||||||
// call the "super" method...
|
// call the "super" method...
|
||||||
object.parentCall(this.prototype.__init__, this)
|
object.parentCall(this.prototype.__init__, this)
|
||||||
@ -322,27 +320,20 @@ var C = object.Constructor('C',
|
|||||||
|
|
||||||
And the same thing while extending...
|
And the same thing while extending...
|
||||||
```javascript
|
```javascript
|
||||||
var D = object.Constructor('D',
|
var D = object.Constructor('D', C,
|
||||||
// this will get mixed into 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
|
### Inheriting from native constructor objects
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
var myArray = object.Constructor('myArray', {
|
var myArray = object.Constructor('myArray', Array, {
|
||||||
__extends__: Array,
|
|
||||||
|
|
||||||
// ...
|
// ...
|
||||||
})
|
})
|
||||||
```
|
```
|
||||||
@ -361,9 +352,7 @@ Extending `.constructor(..)` is not necessary in most cases as
|
|||||||
replacement.
|
replacement.
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
var myArray = object.Constructor('myArray', {
|
var myArray = object.Constructor('myArray', Array, {
|
||||||
__extends__: Array,
|
|
||||||
|
|
||||||
__new__: function(context, ...args){
|
__new__: function(context, ...args){
|
||||||
var obj = Reflect.construct(myArray.__proto__, args, myArray)
|
var obj = Reflect.construct(myArray.__proto__, args, myArray)
|
||||||
|
|
||||||
@ -454,6 +443,7 @@ Define an object constructor
|
|||||||
Constructor(<name>)
|
Constructor(<name>)
|
||||||
Constructor(<name>, <prototype>)
|
Constructor(<name>, <prototype>)
|
||||||
Constructor(<name>, <parent-constructor>, <prototype>)
|
Constructor(<name>, <parent-constructor>, <prototype>)
|
||||||
|
Constructor(<name>, <parent-constructor>, <constructor-mixin>, <prototype>)
|
||||||
Constructor(<name>, <constructor-mixin>, <prototype>)
|
Constructor(<name>, <constructor-mixin>, <prototype>)
|
||||||
-> <constructor>
|
-> <constructor>
|
||||||
```
|
```
|
||||||
|
|||||||
23
object.js
23
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):
|
// Special methods (constructor):
|
||||||
//
|
//
|
||||||
// Handle uninitialized instance construction
|
// Handle uninitialized instance construction
|
||||||
@ -474,7 +464,7 @@ function(context, constructor, ...args){
|
|||||||
// // NOTE: new is optional...
|
// // NOTE: new is optional...
|
||||||
// var A = new Constructor('A')
|
// var A = new Constructor('A')
|
||||||
//
|
//
|
||||||
// var B = Constructor('B', { __extends__: A })
|
// var B = Constructor('B', A, {})
|
||||||
//
|
//
|
||||||
// var C = Constructor('C', B, {})
|
// var C = Constructor('C', B, {})
|
||||||
//
|
//
|
||||||
@ -540,13 +530,12 @@ function Constructor(name, a, b, c){
|
|||||||
|
|
||||||
// handle:
|
// handle:
|
||||||
// Constructor(name, constructor, ..)
|
// Constructor(name, constructor, ..)
|
||||||
if(constructor_proto){
|
constructor_proto
|
||||||
proto.__proto__ === Object.prototype
|
&& proto.__proto__ === Object.prototype
|
||||||
&& (proto.__proto__ = constructor_proto.prototype)
|
&& (proto.__proto__ = constructor_proto.prototype)
|
||||||
|
|
||||||
// handle:
|
// handle: .__extends__
|
||||||
// Constructor(name, ..)
|
if(!constructor_proto){
|
||||||
} else {
|
|
||||||
// handle .__extends__
|
// handle .__extends__
|
||||||
a = Object.hasOwnProperty.call(proto, '__extends__')
|
a = Object.hasOwnProperty.call(proto, '__extends__')
|
||||||
&& proto.__extends__
|
&& proto.__extends__
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user