Reputation: 3560
I need to know what is underscore ( _ )
mean if its write before function, variable, is for just describe something, or its needed to do or execute some of calling function ..etc
JS
var _initMobile ... //variable
_addEvent(documentElement, [EVENT_TOUCHSTART ...) //event handler
PHP
function _getBackLink(&$node, $uri, $title) {}...// php function
In fact, I did not know how to look for it..ٍSo Im ask
Upvotes: 3
Views: 5119
Reputation: 11693
It's good to go by conventions. Why do you make SITE_NAME in caps? Because it's global. Same is here.
In JavaScript:
It means convention for private fields or private methods. Methods that are only for internal use. They should not be invoked outside of the class.
Private fields contain data for internal use. They should not be read or written into (directly) from outside of the class.
Great answer here about PHP:
It's from the bad old days of Object Oriented PHP (PHP 4). That implementation of OO was pretty bad, and didn't include things like private methods. To compensate, PHP developers prefaced methods that were intended to be private with an underscore. In some older classes you'll see
/**private*/ __foo() {
to give it some extra weight.I've never heard of developers prefacing all their methods with underscores, so I can't begin to explain what causes that.
Upvotes: 6
Reputation: 6519
Its just a convention for readability IMO. No access restrictions are imposed by both the languages when a variable or function contains a underscore before it.
Upvotes: 1
Reputation: 60496
Thats only a coding convention. These languages does not interpret the underscore in any way. In most cases thats the way developers use to "mark" the function as private.
Upvotes: 7