The answer to this question will be quite wide, as there are hundreds of examples of using the name property. They are described in detail in the JavaScript documentation . A few of the following examples.
Change the name of a function.
var newName = "xyzName"; var f = function () {}; Object.defineProperty(f, 'name', {value: newName}); console.log(f.name);
To register the class stack, we can get the name of the constructor, as in the following example.
function a() {}; var b = new a(); console.log(b.constructor.name);
Get the name of the function if it is not anonymous.
var getRectArea = function area(width, height) { return width * height; } getRectArea.name;
source share