For example
const Foo = (function () {
const something = [];
const method1 = function(){
bar.addEventListener("click", method2); //how can i access this method from Foo2??
};
return {method1};
})();
const Foo2 = (function () {
const {method1} = Foo(???); //the example ive found that was remotely close
const somethingElse = 10;
const method2 = function(){
//do something
};
return {method2};
})();
In the one example I could find they used object destructuring and set it equal to the other module I want to inherit that one specific function from. I tried to implement this, but it told me Foo wasnt a function, or I was trying to access it without initialization. In there example they had a variable in the parentheses in Foo but applying it to my project idk what to put in the parenthesis, everything I tried was an error, even empty parentheses. Also, I dont know what to put in front of the callback function name in the event listener even if this did work. Ive tried bar.addEventListener("click", Foo2.method2); and bar.addEventListener("click", Foo2.method2()); Ive seen this question asked different ways with several different answers but to be honest the explanations are just above my level of understanding. The object destructuring makes the most sense to me but it still didnt work so idk what to do? I understand prototypal inheritance and being able to say Foo.prototype.someFunction to be able to use the methods inside Foo, but whats the "factory function/module pattern" equivalent of accomplishing this? Not even just the event just how can these two modules connect with each other? Is the syntax wrong, is it not possible?I just want something to go by and example, something. The assignment requires we use factory functions and the module pattern, theres just not any resources on it that I can find for whatever reason. This is javascript btw.
Aucun commentaire:
Enregistrer un commentaire