Created
February 18, 2012 04:05
-
-
Save deoxxa/1857325 to your computer and use it in GitHub Desktop.
pilot object
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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