Toggle navigation
Toggle navigation
This project
Loading...
Sign in
I_Jemin
/
Node-Study
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
I_Jemin
2018-03-22 00:21:31 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
87958a8b97c6ee66d8334749f92949b5b9c3f7ab
87958a8b
1 parent
73113847
Extends Class
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
14 additions
and
21 deletions
app.js
logger.js
app.js
View file @
87958a8
const
EventEmitter
=
require
(
'events
'
);
const
emitter
=
new
EventEmitt
er
();
const
Logger
=
require
(
'./logger
'
);
const
logger
=
new
Logg
er
();
// Register a listener
emitter
.
on
(
'messageLogged'
,
(
arg
)
=>
{
logger
.
on
(
'messageLogged'
,
(
arg
)
=>
{
console
.
log
(
'Listener called'
,
arg
);
});
const
log
=
require
(
'./logger'
);
log
(
'message'
);
logger
.
log
(
'message'
);
...
...
logger.js
View file @
87958a8
const
EventEmitter
=
require
(
'events'
);
const
emitter
=
new
EventEmitter
();
var
url
=
'http:mylogger.io/log'
;
function
log
(
message
)
{
// Send an HTTP request
console
.
log
(
message
);
emitter
.
emit
(
'messageLogged'
,
{
id
:
1
,
url
:
'http://'
});
}
// function in class won't need function keyword
class
Logger
extends
EventEmitter
{
log
(
message
)
{
// Send an HTTP request
console
.
log
(
message
);
//Raise an event
this
.
emit
(
'messageLogged'
,
{
id
:
1
,
url
:
'http://'
});
}
}
module
.
exports
=
log
;
module
.
exports
=
Logger
;
...
...
Please
register
or
login
to post a comment