Инициализатор объекта ( литерал объекта ) в JS выглядит следующим образом:
{
propName: 123,
123: 'some value',
hmmAFunction: function(){}
}
Как правило, он идет PropertyName : AssignmentExpression
с каждой парой ключ / значениечерез запятуюИтак, когда вы делаете это:
return {
POI: function(ID, Title, Section, District, City, Governorate) {
},
// THIS
POI.prototype.getFullAddress = function (opts) {
}
};
... это недопустимо и приведет к ошибкам.
Попробуйте вместо этого:
var Makani = {
POI: (function(){
function POI (ID, Title, Section, District, City, Governorate) {
this.ID = ID;
this.Title = Title;
this.Section = Section;
this.City = City;
this.Goverorate = Governorate;
}
POI.prototype.getFullAddress = function (opts) {
if (("includeCity" in opts) && (opts["includeCity"] == false))
return this.Section + ", " + this.District;
else if (("includeGovernorate" in opts) && (opts["includeGovernorate"] == false))
return this.Section + ", " + this.District + ", " + this.City;
else return this.Section + ", " + this.District + ", " + this.City + ", " + this.Governorate;
};
return POI;
}())
};
Кроме того, я не советую начинать имя переменной с заглавной буквы (например, District
), за исключением случаев, когда она ссылается на функцию конструктора (например, POI
).