Is it possible to get the class calling a function in JavaScript?
For example:
function Foo(){
this.alertCaller = alertCaller;
}
function Bar(){
this.alertCaller = alertCaller;
}
function alertCaller(){
alert(*calling object*);
}
When calling the Foo().alertCaller() i want to output the class Foo() and when calling Bar().alertCaller() I want to outbut Bar(). Is there any way I can do this?
Try this :
function alertCaller(){
alert(this.constructor);
}
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