Languages
[Edit]
EN

JavaScript - get current method reference / currently called method

3 points
Created by:
Marcin
2535

In this short article we would like to show how to get currently called method referencje in JavaScript.

Simple solution:

// use inside method / function
var currentMethod = arguments.callee;

Practical example:

// ONLINE-RUNNER:browser;

function a() {
    var currentMethod = arguments.callee;
    console.log(currentMethod.name);
}

function b() {
    var currentMethod = arguments.callee;
    console.log(currentMethod.name);
    a();
}

b();

 

Hey 👋
Would you like to know what we do?
  • Dirask is online IT community for professionals and hobbyist to share their knowledge and help each other in extraordinary easy way.
  • We welcome everyone
    no matter what the experience,
    no matter how basic the question is,
    this community will help you.