is there any way to get function reference when i'm inside function?
var arrayOfFunction = [ myFunction ];
arrayOfFunction[0]();
function myFunction() {
removeFromArray( thisFunctionReference ) // how to get function self reference here?
};
function removeFromArray(functionRef) {
index = arrayOfFunction.indexOf(functionRef);
if (index > -1) {
arrayOfFunction.splice(index, 1);
}
}
In JavaScript, functions are first class members and thus behave like any other object. You can just refer to it by name like this:
myFunction.property = 5;
function myFunction() {
console.log(myFunction.property) //logs 5
console.log(myFunction) // logs the function
};
myFunction();
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