Javascript Namespace that works in IE/Firefox/Chrome?

Probably you just want this: POI. GetFullAddress: function (opts) { It looks like you're trying to change the prototype, but you're creating an object definition in that particular block. The other way would be to create the return part as a var, then extend the prototype, then return it What you are doing at a simple level is this: x = { name1: value, name2 = value } which isn't valid syntax.

Probably you just want this: POI. GetFullAddress: function (opts) { It looks like you're trying to change the prototype, but you're creating an object definition in that particular block. The other way would be to create the return part as a var, then extend the prototype, then return it.

What you are doing at a simple level is this: x = { name1: value, name2 = value } which isn't valid syntax.

See bclary. Com/2004/11/07/#a-11.1.5 ... You can't have a . In a non-quoted property name.

Furthermore, we don't even want a property called POI.getFullAdress. For the prototype property of an object to be manipulated, that object needs to be reference'able... Hence, doing this whole thing within one object initialiser won't work. See my answer pls.

– 999 Mar 28 at 10:47 Yes, I was trying to boil it down the the basic problem: invalid syntax. The "other way" I suggested is what you did. But for the purpose of what he's trying to do here I don't see the point of adding the getFullAddress to the prototype, why not just add it as a member?

It seems more clear, and you could never create a POI without it anyway since it's inside a function. – jamietre Mar 28 at 10:56 I was initially trying to create a simple javascript object, and then I tried to encapulate in the namespace as above, why using the prototype woulddn't be appropriate after adding it to the namespace function POI(ID, Title, Section, District, City, Governorate) {... and POI.prototype. GetFullAddress = function (opts) {...' – Yehia A.

Salam Mar 28 at 11:20.

An object initialiser (object literal) in JS looks like this: { propName: 123, 123: 'some value', hmmAFunction: function(){} } Generally, it goes PropertyName : AssignmentExpression with each key/value pair separated by a comma. So, when you do this: return { POI: function(ID, Title, Section, District, City, Governorate) { }, // THIS POI.prototype. GetFullAddress = function (opts) { } }; ... it's not valid, and will result in errors being thrown.

Try this instead: 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; }()) }; Also, I advise against starting a variable name with a capital letter (e.g. District) unless what it references is a constructor function (like POI).

Thanks it worked, but after reading more about the prototype object it think I wasn't using it the right way, I mean there no use in attaching the getFullAddress function to all instances instead of adding it to POI class directly. However, when I tried renaming POI.prototype. GetFullAddress to POI.

GetFullAddress I got an error when calling the getFullAddress function after initializing it, var x = new Makani. POI(...), x.getFullAddress().

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions