-
-
Save deoxxa/1857667 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) { | |
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); // <--- Pilot | |
return this; | |
}; | |
var p = new Pilot(); | |
magic_ajax_thing_i_suggest_reqwest({ | |
url: "/some/thing.json", | |
type: "json", | |
success: function(err, data) { | |
p.setAll(data); | |
console.log(p); | |
}, | |
}); | |
console.log(p); |
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
// basically all that matters is how setAll is called | |
// | |
// if you pass it on its own (i.e. {success: p.setAll}) | |
// it'll be called on its own, with `this' being set to the | |
// default global object. in a browser, this is `window'. | |
// if you pass it in wrapped in a function that calls it as | |
// the member of an object (i.e. as above), it'll have | |
// `this' set to the object it's called from. here's an | |
// example: | |
function LOL() { | |
this.herp = "derp"; | |
} | |
LOL.prototype.rage = function() { | |
console.log(this); | |
}; | |
var lol = new LOL(); | |
var a = function() { lol.rage(); } | |
var b = lol.rage; | |
a(); // will dump the `lol' object | |
b(); // will dump the `window' object |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment