mirror of
https://github.com/flynx/object.js.git
synced 2025-10-29 10:30: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:**
|
**Notes:**
|
||||||
- the two approaches (_function_ vs. `.__call__(..)`) will produce
|
- The two approaches (_function_ vs. `.__call__(..)`) will produce
|
||||||
functionally identical but structurally different constructors/objects,
|
functionally identical but structurally different constructors/objects,
|
||||||
the difference is in `.prototype` -- what is defined as the prototype
|
the difference is in `.prototype` -- what is defined as the prototype
|
||||||
_is_ the prototype (_POLS_), so we get:
|
_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
|
The instance in both cases is a function wrapper that will proxy the
|
||||||
call to the corresponding implementation.
|
call to the corresponding implementation.
|
||||||
(this may change in the future)
|
(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
|
### Mix-ins
|
||||||
|
|||||||
15
object.js
15
object.js
@ -315,14 +315,6 @@ function(obj, name, callback, props){
|
|||||||
// and to the method after the match.
|
// and to the method after the match.
|
||||||
// NOTE: this is super(..) replacement, usable in any context without
|
// NOTE: this is super(..) replacement, usable in any context without
|
||||||
// restriction -- super(..) is restricted to class methods only...
|
// 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 =
|
var parent =
|
||||||
module.parent =
|
module.parent =
|
||||||
function(proto, name){
|
function(proto, name){
|
||||||
@ -363,7 +355,6 @@ function(proto, name){
|
|||||||
//
|
//
|
||||||
//
|
//
|
||||||
// This is like parent(..) but will get a property descriptor...
|
// This is like parent(..) but will get a property descriptor...
|
||||||
//
|
|
||||||
var parentProperty =
|
var parentProperty =
|
||||||
module.parentProperty =
|
module.parentProperty =
|
||||||
function(proto, name){
|
function(proto, name){
|
||||||
@ -398,8 +389,6 @@ function(proto, name){
|
|||||||
// or:
|
// or:
|
||||||
// parent(method, this).call(this, ...)
|
// parent(method, this).call(this, ...)
|
||||||
// NOTE: for more docs see parent(..)
|
// NOTE: for more docs see parent(..)
|
||||||
//
|
|
||||||
// XXX in the call case need to skip the wrapper function... (???)
|
|
||||||
var parentCall =
|
var parentCall =
|
||||||
module.parentCall =
|
module.parentCall =
|
||||||
function(proto, name, that, ...args){
|
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
|
// It is however possible to mix related types as we are doing for
|
||||||
// callable instances (Function + Object -- a function is an object).
|
// callable instances (Function + Object -- a function is an object).
|
||||||
// See README.md for more info.
|
// 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 =
|
var Constructor =
|
||||||
module.Constructor =
|
module.Constructor =
|
||||||
// shorthand...
|
// shorthand...
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "ig-object",
|
"name": "ig-object",
|
||||||
"version": "5.0.1",
|
"version": "5.0.2",
|
||||||
"description": "",
|
"description": "",
|
||||||
"main": "object.js",
|
"main": "object.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
27
test.js
27
test.js
@ -67,11 +67,11 @@ var setups = {
|
|||||||
return {
|
return {
|
||||||
A: A = assert(object.C('A',
|
A: A = assert(object.C('A',
|
||||||
function(){
|
function(){
|
||||||
// XXX
|
return 'A'
|
||||||
}), 'callable'),
|
}), 'callable'),
|
||||||
B: B = assert(object.C('B', {
|
B: B = assert(object.C('B', {
|
||||||
__call__: function(){
|
__call__: function(){
|
||||||
// XXX
|
return 'B'
|
||||||
},
|
},
|
||||||
}), 'callable'),
|
}), 'callable'),
|
||||||
|
|
||||||
@ -80,17 +80,25 @@ var setups = {
|
|||||||
|
|
||||||
E: E = assert(object.C('E', A,
|
E: E = assert(object.C('E', A,
|
||||||
function(){
|
function(){
|
||||||
// XXX how do we get the parent callable???
|
assert(
|
||||||
object.parent(this)
|
object.parentCall(E.prototype, '__call__', this, ...arguments) == 'A',
|
||||||
|
'parrent call')
|
||||||
|
return 'E'
|
||||||
}), 'call parent'),
|
}), 'call parent'),
|
||||||
F: F = assert(object.C('F', B, {
|
F: F = assert(object.C('F', B, {
|
||||||
__call__: function(){
|
__call__: function(){
|
||||||
object.parentCall(F.__call__, this)
|
assert(
|
||||||
|
object.parentCall(F.prototype, '__call__', this, ...arguments) == 'B',
|
||||||
|
'parent call')
|
||||||
|
return 'F'
|
||||||
},
|
},
|
||||||
}), 'call parent\'s .__call__'),
|
}), 'call parent\'s .__call__'),
|
||||||
|
|
||||||
|
// XXX not sure about these...
|
||||||
|
a: A(),
|
||||||
|
b: B(),
|
||||||
|
e: E(),
|
||||||
|
f: F(),
|
||||||
} },
|
} },
|
||||||
native: function(assert){
|
native: function(assert){
|
||||||
return {
|
return {
|
||||||
@ -152,6 +160,11 @@ var tests = {
|
|||||||
})
|
})
|
||||||
return {}
|
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