Functions in javascript is also an object and can have properties. So is there any way to access its properties from inside its own function body?
like this
JavaScript
x
6
1
var f = function() {
2
console.log(/*some way to access f.a*/);
3
};
4
f.a = 'Test';
5
f(); //should log 'Test' to console
6
Advertisement
Answer
arguments.callee
is the function itself and doesn’t get affected by the name of the function.
JavaScript
1
6
1
var f = function() {
2
console.log(arguments.callee.a);
3
};
4
f.a = 'Test';
5
f();
6