1

I would like to get the name of a property from within its own function. My current approach does not work because the function is nameless. How can I do this?

window.APP = {
    models: {
        ex_model: kendo.observable({
            ex_property: function () {
                var property_name = arguments.callee.name.toString();
                console.log(property_name);
            },
        }),
    }
}    

Thank you.

xinthose
  • 3,213
  • 3
  • 40
  • 59

1 Answers1

1

You can make ex_property have a name. Instead of using function(), you can say function function_name(), and then arguments.callee.name.toString() would return function_name. Like this:

window.APP = {
    models: {
        ex_model: kendo.observable({
            ex_property: function function_name() {
                var property_name = arguments.callee.name.toString();
                console.log(property_name); // will return function_name
            },
        }),
    }
}
iptq
  • 657
  • 1
  • 7
  • 15
  • yes, I realized this as well, thank you; but I'm trying to shave time off of coding (time = $$) and that would be an extra copy and paste, but still not bad – xinthose Dec 02 '15 at 22:48