Skip to content

Instantly share code, notes, and snippets.

@VinSpee
Created January 14, 2013 23:30
Show Gist options
  • Save VinSpee/4534540 to your computer and use it in GitHub Desktop.
Save VinSpee/4534540 to your computer and use it in GitHub Desktop.
newbing hard on passing the return value of functions
Session.prototype.initialize = function() {
this.bind("change:id", this.onIDChange, this);
if (localStorage.getItem("id" === !null || "")) {
return this.set({
id: localStorage.getItem("id")
});
} else {
console.log("ID not found: " + (this.toJSON()));
this.set({
id: this.getNewID()
});
return console.log(this.toJSON());
}
};
Session.prototype.getNewID = function() {
return $.ajax({
url: "http://localhost:1337/temp-accounts",
type: 'POST',
dataType: "json",
data: {},
success: function(data) {
var newID;
if (data.err) {
return console.log(data.err);
} else {
newID = data.data._id;
return newID;
}
}
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment