Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
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
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?
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 )
......
for now this works for my purpose
if someone has a better way of doing this, pls share.
thanks