help-js
Root Question Message
const arrayFunctions = {
f1: (a)=> {},
f2: (a,b)=> {},
f3: {
test: (a)=>{}
}
}
arrayFunctions
is called? Example: let a = arrayFunctions.f1([1,2]);
let b = arrayFunctions([4,3,2]);
arrayFunctions
is not a function, so you can't call it. You can make it a function and then attach properties to itconst arrayFunctions = () => { /* do some stuff */ };
arrayFunctions.f1 = (a)=> {};
arrayFunctions.f2 = (a,b)=> {};
arrayFunctions.f3 = {
test: (a)=>{}
};
arrayFunctions
function?const subFunctions = {
f1: (a)=> {},
f2: (a,b)=> {},
f3: {
test: (a)=>{}
},
}
const arrayFunctions = () => { /* do some stuff */ };
arrayFunctions.subFunctions = subFunctions;
turnObjectIntoFunction(object, options) {
let temp = object._default
? function (args) {
return object._default(args);
}
: {};
let keys = Object.keys(object);
for (let index = 0; index < keys.length; index++) {
let key = keys[index];
let data = object[key];
if (key !== '_default')
temp[key] =
typeof data == 'object' && !Array.isArray(data) && options?.recursive
? this.turnObjectIntoFunction(data)
: data;
}
return temp;
},
_default
keyturnObjectIntoFunction
before I export my function/object