1

Just to carify, I'm not asking the difference of function declaration and function variable.

For example:

var Klass = function() {};
Klass.prototype._fn1 = function fn1() {};
Klass.prototype._fn2 = function fn2() {};

So, my question is what is the purpose of doing this? Why can't just write:

var Klass = function() {};
Klass.prototype._fn1 = function() {}; // <-- note that the function has no name, it just be assigned to the object as a property
Klass.prototype._fn2 = function() {};
user1481096
  • 317
  • 1
  • 8

1 Answers1

-1

Basically this means you are adding the method _fn1() to Klass Constructor.

Klass.prototype._fn1 = function fn1() {};

And this method is available over the object which is made by using Klass() Constructor.

myObj = new Klass();
myObj._fn1() //you can access the method like this
Suman Bogati
  • 6,289
  • 1
  • 23
  • 34