I've found that sometimes I'll have a var with a bunch of methods and properties that I can't seem to locate somehow, event with Object.keys and Object.getOwnPropertyNames on both the var and the prototype.
Here's an example: I'm playing with RethinkDB and I want to override the run function. However, I don't know where it lives -- what object prototype I need to change, etc. In fact, I can't find any way of finding it with the functions I specified above:
> r.db('test').tableCreate('authors').run
[Function]
> r.db('test').tableCreate('authors')
{ [Function]
args:
[ { [Function] args: [Object], optargs: {} },
{ [Function] data: 'authors' } ],
optargs: {} }
> r.db('test').tableCreate('authors').prototype
{}
> r.db('test').tableCreate('authors').run
[Function]
> Object.keys(r.db('test').tableCreate('authors'))
[ 'args', 'optargs' ]
> typeof r.db('test').tableCreate('authors')
'function'
> Object.getOwnPropertyNames( r.db('test').tableCreate('authors') )
[ 'length',
'name',
'arguments',
'caller',
'prototype',
'args',
'optargs' ]
> Object.getOwnPropertyNames( r.db('test').tableCreate('authors').prototype )
[ 'constructor' ]
The run function never shows up... Any ideas?
EDIT:
I did some snooping in the source code. this is the method I want to wrap.
Then, you can following the inheritance chain from TermBase to Eq (RDBVal, RDBOp, Eq).
r.eq().run returns a function -- the function I want to wrap.
@T.J. Crowder's answer: findProps('run', r.eq()) prints out a bunch of stuff including:
I20150625-10:33:31.047(-7)? Props for run[[Proto]][[Proto]][[Proto]][[Proto]]
I20150625-10:33:31.047(-7)? 0: constructor
I20150625-10:33:31.047(-7)? 1: showRunWarning
I20150625-10:33:31.047(-7)? 2: run
So thats it!
SomeObj.prototype.run = //.... And I have no idea whatSomeObjis. Its returned bytableCreatethough...runsounds like it should be the final link in a chain, though, so you might just be able to define a helper likefunction runWithLogs(obj) { log('pre'); var r = obj.run(); log('post', r); return r; }