File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ <!doctype html>
2+ < html lang ="en ">
3+ < head >
4+ < title > JavaScript Patterns</ title >
5+ < meta charset ="utf-8 ">
6+ </ head >
7+ < body >
8+ < script >
9+ ( function ( ) {
10+
11+ var CarManager = {
12+
13+ /* request information */
14+ requestInfo : function ( model , id ) {
15+ return 'The purchase info for ' + model + ' with ID ' + id + ' is being processed...' ;
16+ } ,
17+
18+ /* purchase the car */
19+ buyVehicle : function ( model , id ) {
20+ return 'You have successfully purchased Item ' + id + ', a ' + model + '.' ;
21+ }
22+
23+ } ;
24+
25+ CarManager . execute = function ( commad ) {
26+ return CarManager [ commad . request ] ( commad . model , commad . carID ) ;
27+ } ;
28+
29+ var actionA = CarManager . execute ( { request : "requestInfo" , model : 'Ford Mondeo' , carID : '543434' } ) ;
30+ console . log ( actionA ) ;
31+ var actionB = CarManager . execute ( { request : "buyVehicle" , model : 'Ford Mondeo' , carID : '543434' } ) ;
32+ console . log ( actionB ) ;
33+
34+ } ) ( ) ;
35+
36+ </ script >
37+ </ body >
38+ </ html >
You can’t perform that action at this time.
0 commit comments