My code:
export default (function () {
(...)
return {
open: () => {
(...)
},
close: () => {
(...)
},
get: () => {
(...)
}
}
})();
I wanna call the close()
in get()
function like this :
get: () => {
close();
}
I tried to use this
but it doesn't work.
Please give me some advice.
Thank you in advance.
Calling a function inside of itself is called recursion. It's a technique used for many applications, like in printing out the fibonacci series.
Calling Function From another Function within Same class – In the below example, the class method Function1 calls method Function2 from the class.
Python also accepts function recursion, which means a defined function can call itself. Recursion is a common mathematical and programming concept. It means that a function calls itself. This has the benefit of meaning that you can loop through data to reach a result.
Either use method properties instead (for which this
rules will work just like with standard non-arrow functions):
export default (function () {
(...)
return {
open() {
(...)
},
close(){
(...)
},
get() {
(...)
this.close();
}
}
})();
Or define all functions that you want to be able to cross-reference before the return
statement:
export default (function () {
(...)
const close = () => {
(...)
};
return {
open: () => {
(...)
},
close,
get: () => {
(...)
close();
}
}
})();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With