1

I am facing some issue or may it something new comes with fat-arrow function while implementing prototype.

Here is the problem::

function baseClass() {
   this.name = "Pankaj";
}

baseClass.prototype.fnGetName = function() {
   return this.name;
};

baseClass.prototype.fatArrayGetName = () => {
  return this.name;
};

var classObject = new baseClass();

Now when I try to retrieve name property of class using methods as:

classObject.name; // returns Pankaj
classObject.fnGetName() // returns Pankaj
classObject.fatArrayGetName() // returns ""    (EMPTY STRING)

Just want to know why fatArrayGetName function return empty string where as it should return name property value.

Pankaj Badukale
  • 1,991
  • 2
  • 18
  • 32
  • That because the Arrow function is binding automatically with the declaration context. – Ele Feb 03 '18 at 14:52
  • is there any way to make it work with prototype context. because i tried with call method as *classObject.fatArrayGetName.call(classObject)* but still it returns empty string – Pankaj Badukale Feb 03 '18 at 14:57

0 Answers0