PDA

View Full Version : Get calling function name.



incutonez
28 Aug 2014, 3:03 PM
I'm curious to know if there's an Ext way of getting the calling function's name without having to use arguments.callee.caller (as that's been deprecated) and naming my functions. Let's say I have this code:



Ext.Loader.setConfig({
enabled: true
});

Ext.define('Mixin', {
logWarning: function logWarning() {
console.log('warning: ' + this.$className + '::' + arguments.callee.toString()); // displays function logWarning() ...
console.log('warning: '+ this.$className + '::' + arguments.callee.caller.toString()); // displays functions() ...
}
});

Ext.define('My.Panel', {
extend: 'Ext.panel.Panel',
mixins: ['Mixin']
});

Ext.application({
name: 'Test',
launch: function() {
Ext.define('MyPanel', {
extend: 'My.Panel',
width: 200,
height: 300,
initComponent: function() {
this.callParent();
this.logWarning();
}
});
Ext.create('MyPanel', {
renderTo: Ext.getBody()
});
}
});


In my logWarning function, the first console.log string shows me the function name because I named the function. However, in most apps, the functions remain anonymous because there's no need, as I'm doing something like this.logWarning, and it doesn't make sense to maintain the same two names in my code.

What I'd like to know is, is there a way of grabbing the calling function's name using some Ext function I'm unaware of? I can easily grab the className with this.$className, but I'm sure that's frowned upon...

skirtle
28 Aug 2014, 4:17 PM
From a quick look at the source for callParent I came up with this, which seems to work:


arguments.callee.caller.$name

incutonez
28 Aug 2014, 4:59 PM
From a quick look at the source for callParent I came up with this, which seems to work:


arguments.callee.caller.$name

Hmm, while that is convenient... I'd rather not use something that's deprecated. I was just hoping Ext stored this information somewhere, but I guess even the framework is leaning on that. Thanks for the answer.