I am writting my first program in JS with an object "formulas" containing functions. Functions will be defined there often with other functions. All of them from "formulas" and I would like to have short, easy access to some of them (like "impl" in the example below).
Now, I manage to do it outside the "formulas", but it makes the code harder to write or read and global variables are not suggested. Could I do it somehow inside and once for each shortcut? I plan to define lambda functions there too.
let formulas = {
"implication": function(x,y) {
return !(x && !y);
},
"impl": function(x,y) {return implication(x,y);},
//a short cut to formulas.implication(x,y) also didn't worked
"non_causality": function(x,y) {
return impl(x,y) === impl(y,x);
}
};
undefined
formulas.non_causality(true, false);
VM32648:9 Uncaught ReferenceError: impl is not defined
at Object.non_causality (<anonymous>:9:4)
at <anonymous>:1:10
non_causality @ VM32648:9
(anonymous) @ VM32656:1
let formulas = {
"implication": function(x,y) {
return !(x && !y);
},
"non_causality": function(x,y) {
return formulas.implication(x,y) === formulas.implication(y,x);
}
};
//undefined
formulas.non_causality(true, false);
//false - This one worked,
//: ] a shortcut "impl" would be helpful though.