mirror of
https://github.com/flynx/object.js.git
synced 2025-10-30 19:10:11 +00:00
docs...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
df2c4ea140
commit
14c26d5f83
26
README.md
26
README.md
@ -402,20 +402,34 @@ to make source printing in console more pleasant to read.
|
|||||||
At this point we can't mix native types, for example it is not possible
|
At this point we can't mix native types, for example it is not possible
|
||||||
to make a callable `Array` object...
|
to make a callable `Array` object...
|
||||||
|
|
||||||
For example this will produce a broken instance:
|
This is not possible in current _JavaScript_ implementations directly
|
||||||
|
as most builtin objects rely on "hidden" mechanics and there is no way
|
||||||
|
to combine or inherit them.
|
||||||
|
|
||||||
|
To illustrate:
|
||||||
```javascript
|
```javascript
|
||||||
var CallablaArray = object.Constructor('CallablaArray', Array, function(){ .. })
|
// produces an Array that looks like a function but does not act like one...
|
||||||
|
var a = Reflect.construct(Array, [], Function)
|
||||||
|
|
||||||
|
// creates a function that looks like an array...
|
||||||
|
var b = Reflect.construct(Function, [], Array)
|
||||||
```
|
```
|
||||||
|
|
||||||
This will produce an instance broken in a different way:
|
So these will produce partially broken instances:
|
||||||
```javascript
|
```javascript
|
||||||
var CallablaArray = object.Constructor('CallablaArray', Array, {
|
var A = object.Constructor('A', Array, function(){ .. })
|
||||||
|
|
||||||
|
var B = object.Constructor('B', Array, {
|
||||||
__call__: function(){ .. },
|
__call__: function(){ .. },
|
||||||
})
|
})
|
||||||
```
|
```
|
||||||
|
|
||||||
Some of this is due to how _object.js_ is currently implemented, this
|
Essentially this issue and the inability to implement it without
|
||||||
needs further investigation...
|
emulation, shows the side-effects of two "features" in _JavaScript_:
|
||||||
|
- lack of multiple inheritance
|
||||||
|
- _hidden_ protocols/functionality (namely: calls, attribute access)
|
||||||
|
|
||||||
|
Still, this is worth some thought.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -513,6 +513,14 @@ function(context, constructor, ...args){
|
|||||||
// X = Constructor('X', Array, function(){})
|
// X = Constructor('X', Array, function(){})
|
||||||
// ...can we "mix" disibilar types in JS, if yes then how do we
|
// ...can we "mix" disibilar types in JS, if yes then how do we
|
||||||
// construct the instance -- which constructor do we call???
|
// construct the instance -- which constructor do we call???
|
||||||
|
// ..this appears not to be possible as:
|
||||||
|
// 1) Reflect.construct(Function, [], Array)
|
||||||
|
// will produce a callable object with access to all the
|
||||||
|
// array methods but none of the low-level mechanics, thus
|
||||||
|
// part of the methods will break like .push(..)
|
||||||
|
// 2) Reflect.construct(Array, [], Function)
|
||||||
|
// will produce an array instnace that looks like a function
|
||||||
|
// but is not callable...
|
||||||
// XXX revise .toString(..) definition test...
|
// XXX revise .toString(..) definition test...
|
||||||
var Constructor =
|
var Constructor =
|
||||||
module.Constructor =
|
module.Constructor =
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user