diff --git a/README.md b/README.md index cc28293..ae3c590 100755 --- a/README.md +++ b/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 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 -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 -var CallablaArray = object.Constructor('CallablaArray', Array, { +var A = object.Constructor('A', Array, function(){ .. }) + +var B = object.Constructor('B', Array, { __call__: function(){ .. }, }) ``` -Some of this is due to how _object.js_ is currently implemented, this -needs further investigation... +Essentially this issue and the inability to implement it without +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. diff --git a/object.js b/object.js index 4fe5c15..0661027 100755 --- a/object.js +++ b/object.js @@ -513,6 +513,14 @@ function(context, constructor, ...args){ // X = Constructor('X', Array, function(){}) // ...can we "mix" disibilar types in JS, if yes then how do we // 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... var Constructor = module.Constructor =