oop - Javascript Namespace that works in IE/Firefox/Chrome -


I'm trying to create a namespace that interprets all our JavaScript classes, though is unavailable: Properties After ID POI.prototype.getFullAddress line (in IE after POI) and in IE9 and Firefox . The second problem occurs when I try to initialize the object var x = new Makani.POI (a, b, c ...) , I get JavaScript errors and var X = Makani has to be used POI (A, B, C ...) What's strange without new keywords I posted a complete code for reference Thank you for your help.

  / * MacKin JavaScript library * / var MacName = function () {var private_var; Function private_method () {// work here} return {POI: function (id, title, section, district, city, governor) {this.ID = ID; This.Title = Title; This.Section = section; this. City = city; this. Gororate = Government; }, POI.prototype.getFullAddress = function (opts) {if ("includeCity" in opts) & amp; Amp; (Opts ["includeCity"] == incorrect)) this refund. + + "," + This.District; Otherwise if ("Add Gortrait" in opts) & amp; Amp; Amp; (Opts ["include"] =) wrong) come back to it + + "," + This. District + "," + It. And return it. Session + "," + It. District + "," + It. Citi + "," + It. GOORORATE; }}; } (); In JS, one ( object literal ) looks like this    

:

  {Pronoun: 123, 123: 'some values', hmmma work: work () {}}   

Normally, it < Code> property name goes: assignmentexpress with each key / value pair separated by a comma. Therefore, when you do this: return {POI: function (id, title, section, district, city, governor) {}, // this POI.prototype.getFullAddress = function Opts)) {}};

... this is not valid, and the resulting errors will be thrown.

Try it instead:

  var Makani = {POI: (function () {function POI (id, title, section, district, city, governor) {this .ID = id; this.Title = title; this.Section = section; this.City = City; Goverorate = Governorate;} POI.prototype.getFullAddress = function (opts) {if ("CTI included" in opts) ; Amp; (opts ["includeCity"] == incorrect)) This refund this. District; And if (in the opts "Include GroveRorate") & amp; Amp; Amp; (Opts ["include"] =) false) Return it. Special + "," + this.District + "," + this.City; And return it back. "+ +", "+ This. District +", "+ this. Citi +", "+ this. Goronetet;}; poi;} ())};   

, I recommend starting a variable name with a capital letter (such as district ), unless this reference is a constructor function (such as POI ). / P>

Comments