node.js - EventEmitter creation -


what difference between following:

new require('events').eventemitter(); 

and

var events = require('events'); new events.eventemitter(); 

the first 1 not working, second 1 - works.

why?

note difference between these lines:

new foo().bar()

... , ...

new foo.bar()

in first case new operator change how foo() function processed: used constructor (with this pointing prototype copy etc.)

but in second case new operator cannot applied foo, latter not invoked: it's bar property called instead. naturally, new here means foo.bar used constructor instead.

and that's happens in example: first case tries apply new require function call, not %require_result%.eventemitter one.


Comments

Popular posts from this blog

authentication - Mongodb revoke acccess to connect test database -

r - Update two sets of radiobuttons reactively - shiny -

ios - Realm over CoreData should I use NSFetchedResultController or a Dictionary? -