Skip to content
Advertisement

Accessing function object’s properties from inside the function body

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

var f = function() { 
  console.log(/*some way to access f.a*/);
};
f.a = 'Test';
f(); //should log 'Test' to console

Advertisement

Answer

arguments.callee is the function itself and doesn’t get affected by the name of the function.

var f = function() { 
  console.log(arguments.callee.a);
};
f.a = 'Test';
f();
Advertisement