Skip to Content
0
Apr 06, 2018 at 10:17 AM

PERSONAS : Best practice to reuse script function?

456 Views Last edit Apr 06, 2018 at 10:59 AM 7 rev

Hi,

Let's say i have a functionality useful_func in a script 'SCRIPT_1' that i want to reuse in another script, 'SCRIPT_2' of the same flavor.

Which option is better for performance ?

1 -

//Inside SCRIPT_2

var myScript = session.utils.getScriptById("SCRIPT_1");
myScript.useful_func();

2 - Using a global javascript ressource

//Inside SCRIPT_1 and SCRIPT_2

globalLibrary = session.utils.include("<GUID>", true);
globalLibrary.useful_func();

Edit :

3 -

//Inside SCRIPT_1
globalLibrary = session.utils.include("<GUID>", true);
globalLibrary.useful_func();
// SCRIPT_2
var myScript = session.utils.getScriptById("SCRIPT_1");
myScript.globalLibrary.useful_func();

Regards,

Alexandre