node.js 이벤트 모듈
이벤트 모듈
node.js에는 Event라는 내장 모듈이 있어 사용자 자신의 이벤트를 생성, 실행 및 수신 할 수 있습니다.
내장 이벤트 모듈을 포함 시키려면 require메소드를 사용합니다.
또한 모든 이벤트 속성 및 메서드는 EventEmitter객체의 인스턴스입니다.
이런한 속성 및 메서드에 액세스 하려면 EventEmitter객체를 만듭니다.
var events = require('event');
var eventEmitter = new event.EventEmitter();
EventEmitter객체
EventEmitter객체를 사용하여 이벤트 핸들러를 자신의 이벤트에 할당 할 수 있습니다.
아래의 예제에서는 scream이벤트가 발생했을 때 실행될 함수를 만들었습니다.
이벤트를 발생시키려면 emit()메소드를 사용합니다.
예)
var events = require('events');
var eventEmitter = new events.EventEmitter();
//Create an event handler:
var myEventHandler = function () {
console.log('I hear a scream!');
}
//Assign the event handler to an event:
eventEmitter.on('scream', myEventHandler);
//Fire the 'scream' event:
eventEmitter.emit('scream');
게시판 목록
개발자팁
개발과 관련된 유용한 정보를 공유하세요.
질문은 QA에서 해주시기 바랍니다.
질문은 QA에서 해주시기 바랍니다.
| 번호 | 분류 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|---|
| 4856 | PHP | 7년 전 | 5738 | ||
| 4855 | jQuery | 7년 전 | 3241 | ||
| 4854 | jQuery | 7년 전 | 2232 | ||
| 4853 | jQuery | 7년 전 | 2837 | ||
| 4852 | MySQL | 7년 전 | 2998 | ||
| 4851 | jQuery | 7년 전 | 2345 | ||
| 4850 | jQuery | 7년 전 | 2574 | ||
| 4849 | jQuery | 7년 전 | 4312 | ||
| 4848 | PHP |
|
7년 전 | 4249 | |
| 4847 | jQuery | 7년 전 | 4023 | ||
| 4846 | jQuery | 7년 전 | 2641 | ||
| 4845 | jQuery | 7년 전 | 2158 | ||
| 4844 | jQuery | 8년 전 | 2306 | ||
| 4843 | jQuery | 8년 전 | 3058 | ||
| 4842 | jQuery | 8년 전 | 2902 | ||
| 4841 | jQuery | 8년 전 | 2231 | ||
| 4840 | jQuery | 8년 전 | 1572 | ||
| 4839 | jQuery | 8년 전 | 2469 | ||
| 4838 | jQuery |
이에스씨코리아
|
8년 전 | 2323 | |
| 4837 | jQuery | 8년 전 | 2171 | ||
| 4836 | jQuery | 8년 전 | 2095 | ||
| 4835 | jQuery | 8년 전 | 1829 | ||
| 4834 | jQuery | 8년 전 | 1869 | ||
| 4833 | jQuery | 8년 전 | 1996 | ||
| 4832 | jQuery | 8년 전 | 2187 | ||
| 4831 | jQuery | 8년 전 | 2366 | ||
| 4830 | jQuery | 8년 전 | 2633 | ||
| 4829 | jQuery | 8년 전 | 1806 | ||
| 4828 | jQuery | 8년 전 | 2751 | ||
| 4827 | jQuery | 8년 전 | 2291 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기