Estoy tratando de llamar a una función dentro de una función fuera de la principal:
var myFunction = function myFunct(element) { function tryIt(){ alert("hello"); }; return{ tryIt: tryIt } }Y trato de llamar a la función "tryIt" fuera de myFunct con
myFunction.tryItPero no funciona.
¿Cómo puedo hacer esto?
Primero, debe llamar a la función y luego llamar a la función del objeto devuelto de la propiedad tryIt .
var myFunction = function myFunct(element) { function tryIt(){ alert("hello"); } return { tryIt: tryIt }; }; myFunction().tryIt(); // ^^ calls myFunction // ^^^^^^^^^ returns object with function tryIt // ^^ calls tryItfunction myFunct() { function tryIt() { console.log("hi"); } return { tryIt: tryIt }; } var foo = myFunct(); foo.tryIt();