Is it possible to determine the property name of an anonymous function within the function? For instance...
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Testing</title>
<script type="text/javascript">
var $={};
$.fn={};
$.fn.somePropertyName = function() {
console.log(this); // Object { somePropertyName=function()}
//How do I get "somePropertyName" here?
};
$.fn.somePropertyName()
</script>
</head>
<body></body>
</html>
My purpose is so I don't need to type out "myPluginName" twice when creating jQuery plugins. Not that I am lazy, but don't want the chance of a difference.
$.fn.myPluginName= function(method) {
if (methods[method]) {
return methods[method].apply(this, Array.prototype.slice.call(arguments, 1));
} else if (typeof method === 'object' || ! method) {
return methods.init.apply(this, arguments);
} else {
// Somehow get the property name "myPluginName" here.
$.error('Method ' + method + ' does not exist on jQuery.myPluginName');
}
};