• 0

function _functionName


Question

I've noticed while looking through some jQuery plugins, programmers are using _ before their function names, sometimes even ___ ( _ 3 times). What does this reference to? Here's an example...

function _disable_keyboard_navigation() {
			$(document).unbind();
		}

Link to comment
Share on other sites

6 answers to this question

Recommended Posts

  • 0

It doesn't particularly mean anything, you can have underscores anywhere in a function name. Developers usually put underscores in front of function names to denote functions that they're only supposed to be used internally by the API your using, and that you shouldn't use them yourself. There's nothing to say that you can't, since JavaScript is totally open, but its not recommended in most cases.

... There are a few exceptions that are worth noting, such as the __doPostBack function that comes with the ASP.NET JavaScript, which (although not recommended by Microsoft) can be very useful when writing your own JavaScript.

Link to comment
Share on other sites

  • 0

It doesn't particularly mean anything, you can have underscores anywhere in a function name. Developers usually put underscores in front of function names to denote functions that they're only supposed to be used internally by the API your using, and that you shouldn't use them yourself. There's nothing to say that you can't, since JavaScript is totally open, but its not recommended in most cases.

... There are a few exceptions that are worth noting, such as the __doPostBack function that comes with the ASP.NET JavaScript, which (although not recommended by Microsoft) can be very useful when writing your own JavaScript.

Ah, so it's more so for developer reference. Almost a legend you could say.

Link to comment
Share on other sites

  • 0

Ah, so it's more so for developer reference. Almost a legend you could say.

Yeah, basically. Prefixing underscores basically says "Do not use me", although its only a warning ;).

Link to comment
Share on other sites

  • 0

It's to denote a "private function" in languages which don't support. In other words, you can't necessarily rely on it to not change in the future; you should only use public methods.

Link to comment
Share on other sites

  • 0

Yeah I should probably have mentioned that because underscored functions aren't intended for public use, there's a risk that they might change in future, or removed altogether. So you should be careful if you intend to use one, and be aware of the risks.

Link to comment
Share on other sites

  • 0

Yeah, basically. Prefixing underscores basically says "Do not use me", although its only a warning ;).

Makes sense :) Thanks for the info!

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.