mirror of
https://github.com/flynx/object.js.git
synced 2025-10-29 02:20:08 +00:00
cleanup + docs + tweaking...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
a5bab42336
commit
fd19554f1f
@ -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 `<obj> instanceof Function`
|
||||
will be `true`, though `typeof(<obj>) == 'function'`will always work.
|
||||
To satisfy the `instanceof Function` test the prototype tree must be
|
||||
rooted in `Function`.
|
||||
|
||||
|
||||
### Mix-ins
|
||||
|
||||
15
object.js
15
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...
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "ig-object",
|
||||
"version": "5.0.1",
|
||||
"version": "5.0.2",
|
||||
"description": "",
|
||||
"main": "object.js",
|
||||
"scripts": {
|
||||
|
||||
27
test.js
27
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) }) },
|
||||
}
|
||||
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user