Suppose I have an 2 objects x and y. The details are written in the code below.
let x = {
publish: function() {
console.log(this.publish.name);
}
};
let y = {};
y.publish = function() {
console.log(this.publish.name);
};
x.publish();
y.publish();
I was getting difference in the outputs calling x.publish() and y.publish().
The former returned the name of the function while the latter returned empty. Can anyone explain why is this happening, and is there any other
possible way I can retrieve the function name in latter(WITHOUT HARDCODING). I am using NodeJs version 8.