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)); 

see how access correct `this` context inside callback?.


Comments

Popular posts from this blog

apache - setting document root in antoher partition on ubuntu -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -

r - Quantstrat logical error while running applySignals - missing value where TRUE/FALSE needed -