1

What is the difference between

prototype.somefunction()

and

prototype._anotherfunction()

I know this might be trivial, but I couldn't find it.

Drew Noakes
  • 266,361
  • 143
  • 616
  • 705
Saransh Mohapatra
  • 8,542
  • 10
  • 33
  • 48

2 Answers2

4

One has an underscore in the name. There's no difference as far as the javascript engine itself is concerned.

However, it's a common convention to name "private" methods such that they start with an underscore.

starwed
  • 2,189
  • 2
  • 22
  • 36
  • Its a convention? So that means in javascript terms its actually a function which can be called on the object by anyone? – Saransh Mohapatra Mar 12 '14 at 17:12
  • @SaranshMohapatra Yes, it's just a sign to maybe think twice before doing so. (And in a library, an indication that there's a way higher chance of it breaking on an upgrade.) – starwed Mar 12 '14 at 17:59
1

_ prefix means that method is supposed to be private, not more than that

Vytalyi
  • 1,351
  • 3
  • 17
  • 29