我正在用 js 编写自定义 UI 构建器。它使用工厂的实现来构建元素。为了确保清楚哪些函数是库的一部分,哪些是普通的旧 javascript 的一部分,我使用了function _FunctionName()
. 但是,我发现总是做Factory._FunctionName()
.
我应该删除命名约定(function FunctionName()
)还是坚持它?
关于制作这样的库,是否有命名约定常见/最佳实践?
编辑:
var __PanelFactory = function () {
//"private"
var Panels = [];
//exposed
function _GetPanel(id) {
//etc
}
return {
_GetPanel: _GetPanel,
};
};
var Factory = new __PanelFactory();
Factory. //this will show certain plain javascript functions
//like toString, constructor, hasOwnProperty, isPrototypeOf, etc...
//note that even jQuery can have the previous list used with something like
$(selector).
//So to differentiate I made sure my functions start with _
Factory._GetPanel(1);
//Should I just make it easy on myself and allow
Factory.GetPanel(1);
//Or is there value in leaving the naming convention in?