【发布时间】:2011-07-24 09:09:46
【问题描述】:
我正在尝试创建一个命名空间来封装我们所有的 javascript 类,但是在 ie9 和 POI.prototype.getFullAddress 上的 ie9 和 firefox 之后得到一个 missing : after property id > 线(POI 后的停靠点)。第二个问题是当我尝试初始化对象 var x = new Makani.POI(a,b,c...) 我得到 javascript 错误并且必须使用 var x = Makani .POI(a,b,c...) 没有新的关键字,这很奇怪。我发布了完整的代码以供参考。感谢您的帮助。
/* Makani Javascript Libraries */
var Makani = function () {
var private_var;
function private_method() {
// do stuff here
}
return {
POI: function(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;
}
};
} ();
【问题讨论】:
标签: javascript oop namespaces