Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Qlik Connect 2026 Agenda Now Available: Explore Sessions
cancel
Showing results for 
Search instead for 
Did you mean: 
edwin
Master II
Master II

adding parameters to function call

hi,  im creating an extension and it is working fine.  all my code is in one js file (main file) i wish to separate out the helper functions in a different js file.  for functions that dont require parameters i used the following format:

define( [], function () {
	'use strict';
	...
    return ...
});

and it is working great.  now i wish to create a js file with a function that requires a parameter.  how do i code the js file? 

where do i insert the params?  if i do the following it wont work:

define( [], function (param1, param2) {
	'use strict';
	...
    return ...
});

thanks
 

2 Replies
edwin
Master II
Master II
Author

i used the following and it worked:

define( [], function () {
	'use strict';
    return function (param) { console.log(param)}
});

but does this mean you can only create one function per js file?  how do you create a separate js file with all your different functions each requiring a parameter pretty much like a library?

edwin
Master II
Master II
Author

quick and dirty test:

define( [], function () {
	'use strict';
    return {
		len: function (thisArray)   {return thisArray.length},
		sortit: function (thisArray)   {thisArray.sort(); return thisArray}
		}

});

 

define(["./arrayFunctions"],
    function (arrayFunction ) {
        return {
            paint: function ($element, layout) {
			...
				var arr=[98, 18, 100, 17, 24, 34];
				console.log('arr ', arr);
				console.log('len: ', arrayFunction.len(arr))
				arrayFunction.sortit(arr)
				console.log('sorted: ',arr )

......

 

edwin_0-1624022509242.png

for now this works for my purpose

if someone has a better way of doing this, pls share.

thanks