Link to home
Start Free TrialLog in
Avatar of ambuli
ambuliFlag for United States of America

asked on

Calling objects based on string type in javascript

I have the following code snippet where I want to invoke commands on different objects based on the type given.
How can I do this object oriented way in JavaScript.

function(reportTye){
	if( reportType == "REPORT_ONE"){
                   rep1Cmd = new ReportOne();
                   rep1Cmd .run();
          } else if( reportType ==  "REPORT_TWO"){
                 rep2Cmd = new ReportTwo();
		 rep2Cmd .run();
           } else if( reportType ==  "REPORT_THREE"){
                  rep3Cmd = new ReportThree();
		  rep3Cmd .run();
          }

Open in new window

SOLUTION
Avatar of Rob
Rob
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ambuli

ASKER

Thank you guys.  Both are good solutions.  I was looking for something similar to Hielo