I am trying to get the name of a JavaScript instance or class method (in client-side/browser JS) while using the following OOP style for AMD modules (for usage with RequireJS):
define([...], function(...) {
var FooBar = function() {
//Constructor code...
};
FooBar.foo = function() {
//This is a FooBar class method named "foo". How do I get its name from here?
//...
};
FooBar.prototype.bar = function() {
//This is a FooBar instance method named "bar". How do I get its name from here?
//...
};
});
I have seen various posts explaining how to do it in case of named functions, e.g., function foobar() {...}, but not in case of assigned anonymous functions, e.g., foobar = function() {...}.
The latter is relevant here, unless the above can be rewritten using named functions instead.
I would rather not revert to some naming-scheme convention such as foobar = function foobar_extra_name() {...}, since this involves naming a function twice. Furthermore, even if this were possible, it would still not be possible to do something like FooBar.prototype.bar = function FooBar.prototype.bar() {...} because of the dot notation, so it wouldn't be of much help.
Any thoughts about this? Any help is greatly appreciated.