node.js - Passing a function as parameter in javascript, undefined error -
i have function part of object called server
, i.e server.log function use log data. there other properties of server not want pass other functions, though want server.log available functions in other files.
function test() { testingthis(server.log); } function testingthis(logf) { logf("test123"); }
i error saying
cannot read property 'emit' of undefined
i using happy console module log (server.log works fine in test function).
presumably server.log
expects this
refer server
. however, way call function, this
refers global object or undefined
(in strict mode).
bind function server
:
testingthis(server.log.bind(server));
Comments
Post a Comment