mirror of
https://github.com/flynx/object.js.git
synced 2025-10-29 02:20:08 +00:00
minor bugfix + doc tests...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
51f8335f0c
commit
b2741f958f
@ -292,6 +292,7 @@ function(obj){
|
||||
throw new Error(`create(..): invalid name: "${name}"`) } }
|
||||
// calable...
|
||||
if(typeof(obj) == 'function'){
|
||||
/* c8 ignore next 9 */
|
||||
var func = function(){
|
||||
return '__call__' in func ?
|
||||
func.__call__(this, ...arguments)
|
||||
@ -710,9 +711,12 @@ function(func){
|
||||
: '__call__' in this ?
|
||||
this.__call__
|
||||
: this.__proto__)
|
||||
return module.normalizeIndent(f.toString(...args)) },
|
||||
/*/
|
||||
return typeof(f) == 'function' ?
|
||||
module.normalizeIndent(f.toString(...args))
|
||||
: undefined },
|
||||
//*/
|
||||
enumerable: false,
|
||||
})
|
||||
return func }
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "ig-object",
|
||||
"version": "5.5.5",
|
||||
"version": "5.5.6",
|
||||
"description": "",
|
||||
"main": "object.js",
|
||||
"scripts": {
|
||||
|
||||
72
test.js
72
test.js
@ -619,14 +619,18 @@ var tests = test.Tests({
|
||||
|
||||
var cases = test.Cases({
|
||||
'edge-cases': function(assert){
|
||||
// bad names...
|
||||
assert.error('Constructor(..): malformed name',
|
||||
function(){
|
||||
var X = object.Constructor('bad name', {}) })
|
||||
assert.error('create(..): malformed name',
|
||||
function(){
|
||||
object.create('bad name', function(){}) })
|
||||
|
||||
assert.error('double __extends__ fail', function(){
|
||||
var X = object.C('X', {
|
||||
__extends__: Object,
|
||||
}, {
|
||||
__extends__: Function,
|
||||
})
|
||||
})
|
||||
var X = object.C('X',
|
||||
{ __extends__: Object },
|
||||
{ __extends__: Function }) })
|
||||
|
||||
// native constructor...
|
||||
assert.array(
|
||||
@ -674,6 +678,7 @@ var cases = test.Cases({
|
||||
object.values(obj, 'x', function(){ return object.STOP(555) }, true)[0] == 555,
|
||||
// XXX assert ignores the order here -- this should fail...
|
||||
'.values(.., func, true) with explicit stop value')
|
||||
|
||||
},
|
||||
deepKeys: function(assert){
|
||||
var a = {
|
||||
@ -813,6 +818,61 @@ var cases = test.Cases({
|
||||
assert.array(b(), ['A', 'B'], 'call')
|
||||
assert.array(c(), ['A', 'B', 'C'], 'call')
|
||||
},
|
||||
|
||||
'docs': function(assert){
|
||||
|
||||
var func = function(){
|
||||
console.log('some string...') }
|
||||
var func_w_tostring = Object.assign(
|
||||
function(){
|
||||
console.log('some string...') },
|
||||
{ toString: function(){
|
||||
return 'func_w_tostring(){ .. }' } })
|
||||
|
||||
assert(
|
||||
object.create(func).toString() == object.normalizeIndent(func.toString()),
|
||||
'create(..): function .toString() proxy (builtin).')
|
||||
assert(
|
||||
object.create(func_w_tostring).toString() == func_w_tostring.toString(),
|
||||
'create(..): function .toString() proxy (custom).')
|
||||
|
||||
var callable_a =
|
||||
object.Constructor('callable_a',
|
||||
function(){
|
||||
console.log(this.constructor.name) })()
|
||||
var callable_b =
|
||||
object.Constructor('callable_b', {
|
||||
__call__: function(){
|
||||
console.log(this.constructor.name) },
|
||||
})()
|
||||
var callable_c =
|
||||
object.Constructor('callable_c', {
|
||||
__call__: function(){
|
||||
console.log(this.constructor.name) },
|
||||
toString: function(){
|
||||
return this.constructor.name + '.toString()' },
|
||||
})()
|
||||
|
||||
assert(
|
||||
callable_b.toString() == object.normalizeIndent(callable_b.__call__.toString()),
|
||||
'toString(..) proxy to .__call__(..)')
|
||||
assert(
|
||||
callable_b.toString() != object.normalizeIndent(callable_b.__proto__.toString()),
|
||||
'toString(..) proxy not to .__proto__.toString(..)')
|
||||
assert(
|
||||
callable_c.toString() == callable_c.__proto__.toString(),
|
||||
'toString(..) proxy to .toString(..)')
|
||||
|
||||
assert(
|
||||
object.create(callable_a).toString() == callable_a.toString(),
|
||||
'create(..): callable .toString() proxy (func).')
|
||||
assert(
|
||||
object.create(callable_b).toString() == callable_b.toString(),
|
||||
'create(..): callable .toString() proxy (__call__).')
|
||||
assert(
|
||||
object.create(callable_c).toString() == callable_c.toString(),
|
||||
'create(..): callable .toString() proxy (__call__ w. custom toString).')
|
||||
},
|
||||
})
|
||||
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user