在查看各种PHP库时,我注意到很多人选择使用单个下划线为某些类方法添加前缀,例如
public function _foo()
Run Code Online (Sandbox Code Playgroud)
...代替...
public function foo()
Run Code Online (Sandbox Code Playgroud)
我意识到这最终归结为个人偏好,但我想知道是否有人对这种习惯的来源有所了解.
我的想法是,它可能是从PHP 4继承的,在类方法可以被标记为受保护或私有之前,作为暗示"不要从类外调用此方法"的一种方式.然而,我也想到它可能起源于我不熟悉的某个地方(一种语言),或者背后可能有很好的推理,我会从中获益.
任何想法,见解和/或意见将不胜感激.
var Gallery = Backbone.Controller.extend({
_index: null,
_photos: null,
_album :null,
_subalbums:null,
_subphotos:null,
_data:null,
_photosview:null,
_currentsub:null,
routes: {
"": "index",
"subalbum/:id": "subindex",
"subalbum/:id/" : "directphoto",
"subalbum/:id/:num" : "hashphoto"
},
initialize: function(options) {
var ws = this;
if (this._index === null){
$.ajax({
url: 'data/album1.json',
dataType: 'json',
data: {},
success: function(data) {
ws._data = data;
ws._photos =
new PhotoCollection(data);
ws._index =
new IndexView({model: ws._photos});
Backbone.history.loadUrl();
}
});
return this;
}
return this;
},
//Handle rendering the initial view for the
//application
index: function() …Run Code Online (Sandbox Code Playgroud)