我想有2个班(厂区)在我的模块angularjs工厂的内部函数不是工厂的依赖?
angular.module('starter.services', [])
.factory("TPreferences",function($cordovaSQLite){
_set = function(pName, pValue){
console.log("Setting: "+pName+":"+pValue);
}
_addList = function(pList){
for(var p=0; p < pList.length; p++)
{
_set(pList[p].name, pList[p].value);
}
}
return {
init: function(){
_addList(gSettings);
}
}
})
.factory("TDayList",function($cordovaSQLite){
_add = function(pName, pValue){
console.log("Day: "+pName+":"+pValue);
}
_addList = function(pList){
for(var p=0; p < pList.length; p++)
{
_add(pList[p].name,pList[p].value);
}
}
return {
init: function(){
_addList(gExampleDays);
}
};
});
问题:当调用TPreferences.init(), “日:......” 被记录。 我假设“.factory(...)” - 东西是一个类,其中_addList是一个受保护的函数,但似乎_addList似乎是(至少模块范围)全局,并被第二个定义覆盖即使在不同的工厂也有相同的名称。
问题:当然,我可以在这个例子中简单地改变一个函数的名字,但我更喜欢像类一样处理工厂,这样我就可以使用两次内部函数的名字。那么,最聪明的方法是什么?
它是那么容易:)感谢很多 –