Skip to content

Instantly share code, notes, and snippets.

@deoxxa
Created February 18, 2012 04:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save deoxxa/1857325 to your computer and use it in GitHub Desktop.
Save deoxxa/1857325 to your computer and use it in GitHub Desktop.
pilot object
var Pilot = function(data) {
this.charID = 0;
this.charName = null;
this.solarSystemID = null;
this.solarSystemName = null;
this.shipTypeID = null;
this.shipTypeName = null;
this.shipID = null;
this.shipName = null;
this.stationID = null;
this.stationName = null;
this.corpID = null;
this.corpName = null;
this.allianceID = null;
this.allianceName = null;
if (typeof data === "object") {
this.setAll(data);
}
};
Pilot.prototype.setAll = function(data) {
console.log(this); // <--- window element ?
console.log(data); // <--- correct, shows a object with properties below
this.charID = data.charID;
this.charName = data.charName;
this.solarSystemID = data.solarSystemID;
this.solarSystemName = data.solarSystemName;
this.shipTypeID = data.shipTypeID;
this.shipTypeName = data.shitTypeName;
this.shipID = data.shipID;
this.shipName = data.shipName;
this.stationID = data.stationID;
this.stationName = data.stationName;
this.corpID = data.corpID;
this.corpName = data.corpName;
this.allianceID = data.allianceID;
this.allianceName = data.allianceName;
console.log(this); // <--- incorrect, sets attributes to windows
return this;
};
var p = new Pilot({
charID: 5,
charName: "character name",
solarSystemID: 6,
solarSystemName: "solar system",
shipTypeID: 7,
shipTypeName: "ship type",
shipID: 8,
shipName: "ship",
stationID: 9,
stationName: "station",
corpID: 10,
corpName: "corp",
allianceID: 11,
allianceName: "alliance",
});
console.log(p);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment