티스토리 뷰
- 호출을 캡슐화 한다.
- 어떤 때 쓰면 좋을까 ? ( 내생각 )
- 프로그램이 처리 댈 때 매 요청 마다 검증이 필요할때
- 혹은 요청을 가공할 때
- 혹은 요청을 되돌리거나, 요청에 대한 기록을 할 때 ..
- 혹은 요청에 일괄 실행이나 특정 부분까지만 실행 하도록 할때 !
var employee = function(){};
employee.prototype = {
call : function(){
alert('can i help you?');
},
orderup : function() {
alert('did you choose the menu? ');
}
}
var employeeCall = function(emp) {
this.employee = emp;
};
employeeCall.prototype.execute = function(){
this.employee.call();
}
var orderMenu = function(emp){
this.employee = emp;
};
orderMenu.prototype.execute = function(){
this.employee.orderup();
};
//execute
//cust
var outBackCommand = function(){
this.menu = [];
};
outBackCommand.prototype = {
addCommand : function(menu) {
this.menu[this.menu.length] = menu;
},
runCommand : function(){
for(var i=0; i< this.menu.length ; i++) {
this.menu[i].execute();
}
}
};
// Run.
var ob = new outBackCommand();
var emp = new employee();
ob.addCommand(new employeeCall(emp));
ob.addCommand(new orderMenu(emp));
ob.runCommand();
'웹개발 > Javascript' 카테고리의 다른 글
| 자바스크립트 With Statements (0) | 2010.09.10 |
|---|---|
| 자바스크립트 정규식 예제 (0) | 2010.09.10 |
| 자바스크립트 함수, Timer 사용하기 (0) | 2010.09.10 |
| 템플릿 메서드 패턴 (0) | 2010.07.15 |
| 자바스크립트 Observer 패턴 예제 (1) | 2010.07.05 |
댓글