diff --git a/README.md b/README.md index c0073be..a7b75b4 100755 --- a/README.md +++ b/README.md @@ -291,7 +291,7 @@ case. **Notes:** -- the two approaches (_function_ vs. `.__call__(..)`) will produce +- The two approaches (_function_ vs. `.__call__(..)`) will produce functionally identical but structurally different constructors/objects, the difference is in `.prototype` -- what is defined as the prototype _is_ the prototype (_POLS_), so we get: @@ -303,6 +303,10 @@ case. The instance in both cases is a function wrapper that will proxy the call to the corresponding implementation. (this may change in the future) +- Making an object callable does not guarantee that ` instanceof Function` + will be `true`, though `typeof() == 'function'`will always work. + To satisfy the `instanceof Function` test the prototype tree must be + rooted in `Function`. ### Mix-ins diff --git a/object.js b/object.js index d6d347a..9d6e0ef 100755 --- a/object.js +++ b/object.js @@ -315,14 +315,6 @@ function(obj, name, callback, props){ // and to the method after the match. // NOTE: this is super(..) replacement, usable in any context without // restriction -- super(..) is restricted to class methods only... -// -// XXX need to be able to get a callable prototype... -// parent(proto, '__call__') -// This would need to handle two cases transparently: -// - parent with .__call__(..) defined... -// - parent with callable prototype... -// ...should this be handled here or in sources(..)??? -// XXX document both __call__ cases... var parent = module.parent = function(proto, name){ @@ -363,7 +355,6 @@ function(proto, name){ // // // This is like parent(..) but will get a property descriptor... -// var parentProperty = module.parentProperty = function(proto, name){ @@ -398,8 +389,6 @@ function(proto, name){ // or: // parent(method, this).call(this, ...) // NOTE: for more docs see parent(..) -// -// XXX in the call case need to skip the wrapper function... (???) var parentCall = module.parentCall = function(proto, name, that, ...args){ @@ -799,6 +788,10 @@ function(context, constructor, ...args){ // It is however possible to mix related types as we are doing for // callable instances (Function + Object -- a function is an object). // See README.md for more info. +// NOTE: making an object callable does not guarantee that it will pass +// the instanceof Function test, for that the prototype chain needs +// to be rooted in Function. +// though the typeof(..) == 'function' will always work. var Constructor = module.Constructor = // shorthand... diff --git a/package.json b/package.json index 85ac49b..bdd161b 100755 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ig-object", - "version": "5.0.1", + "version": "5.0.2", "description": "", "main": "object.js", "scripts": { diff --git a/test.js b/test.js index dac1e0f..5f57ae7 100755 --- a/test.js +++ b/test.js @@ -67,11 +67,11 @@ var setups = { return { A: A = assert(object.C('A', function(){ - // XXX + return 'A' }), 'callable'), B: B = assert(object.C('B', { __call__: function(){ - // XXX + return 'B' }, }), 'callable'), @@ -80,17 +80,25 @@ var setups = { E: E = assert(object.C('E', A, function(){ - // XXX how do we get the parent callable??? - object.parent(this) + assert( + object.parentCall(E.prototype, '__call__', this, ...arguments) == 'A', + 'parrent call') + return 'E' }), 'call parent'), F: F = assert(object.C('F', B, { __call__: function(){ - object.parentCall(F.__call__, this) + assert( + object.parentCall(F.prototype, '__call__', this, ...arguments) == 'B', + 'parent call') + return 'F' }, }), 'call parent\'s .__call__'), - - + // XXX not sure about these... + a: A(), + b: B(), + e: E(), + f: F(), } }, native: function(assert){ return { @@ -152,6 +160,11 @@ var tests = { }) return {} }, + callables: function(assert, setup){ + return instances(setup) + .map(function([k, o]){ + return typeof(o) == 'function' + && assert(o(), 'call', k) }) }, }