cancel
Showing results for 
Search instead for 
Did you mean: 

calling two functions in a single line of code?

Highlighted
Contributor

calling two functions in a single line of code?

Question: I want to call functions from a single point.

 

Ex:

 

1.

Function Test1()

{

}

 

2.

Function Test2()

{

}

 

  • I need to call the above two functions in single point or single line of code.

 

How do we handle this kind of scripting?

6 REPLIES 6
Highlighted
Community Hero

Re: calling two functions in a single line of code?

The question does not make sense, Why you want to call two functions in single line?


Thanks
Shankar R

LinkedIn | CG-VAK Software | Bitbucket | shankarr.75@gmail.com

“You must expect great things from you, before you can do them”


Extension Available

Highlighted
Occasional Contributor

Re: calling two functions in a single line of code?

Can you be more specific like exactly what you want to do?

Calling multiple functions in a single line makes sense when all the methods return some value and combined output is required for further processing.

 

If you can provide more details on the question(like the use of methods,need of calling 2 functions in the same line), that will be better.

 

Thanks,

Sushant

Highlighted
Contributor

Re: calling two functions in a single line of code?

Yes, I know but it is req from the client. In test complete we can import functions from unit 1 to unit 2 and call them , that's easy, Client not statisfied with that. Can we use Onclick event to call two fucntions ? for example in javascript.

Highlighted
Community Hero

Re: calling two functions in a single line of code?

Hi,

 

Still not sure about actual problem and use case that caused it. Can you describe it with more details?
The simple and obvious solution is to create a third function that will call required two ones and call this function. Technically it will be one-liner.
But something tells me that this is not what you are looking for.
(If you are looking for concurrent code execution (like calling different functions from two different threads), then this is not possible in scripting languages.)

 

Regards,
  /Alex [Community Hero]
____
[Community Heroes] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Heroes]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Hero] signature is used with permission by SmartBear Software.
https://community.smartbear.com/t5/custom/page/page-id/hall-of-fame
================================
Highlighted
Contributor

Re: calling two functions in a single line of code?

 

 

Got the solution from Smartbear.

 

In JavaScript, store your functions in the arrays and call them using key values. Here is the example code:

function f(){
  let dyn_functions = [];
  dyn_functions['Test1'] = function (arg1, arg2) { 
                  return arg1 - arg2
             };
  dyn_functions['Test2'] = function (arg1, arg2) { 
                  return arg1 + arg2
             };
  // calling one of the functions
  let result = dyn_functions['Test1'](1, 2);
  // this works as well
  let result2 = dyn_functions.Test2(1, 2);  

  Log.Message("")
}

 

Thanks everyone for looking into the issue.

Highlighted
Community Hero

Re: calling two functions in a single line of code?

Still did not get use case and thus the actual need and the principal difference of the suggested solution from just calling two functions from the third one (the wrapper)...
But the above is irrelevant as long as you are satisfied with the suggested approach.

 

Regards,
  /Alex [Community Hero]
____
[Community Heroes] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Heroes]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Hero] signature is used with permission by SmartBear Software.
https://community.smartbear.com/t5/custom/page/page-id/hall-of-fame
================================
New Here?
Join us and watch the welcome video:
Announcements
Join TechCorner Challenge!
Want a fun and easy way to learn TestComplete? Try solving weekly TechCorner challenges and get into the Leaderboard!

Challenge Status

Changing options from outside of TestComplete

Participate!

How to execute remote test and obtain results via Test Runner REST API

Participate!

Comparing content of HTML table with Excel file data

Participate!

Compare HTML table with Excel file and correct data in the file

Participate!
Top Kudoed Authors