Skip to content

Instantly share code, notes, and snippets.

@bernardo-cs
Created February 17, 2016 10:02
Show Gist options
  • Select an option

  • Save bernardo-cs/8a86f636d45423618209 to your computer and use it in GitHub Desktop.

Select an option

Save bernardo-cs/8a86f636d45423618209 to your computer and use it in GitHub Desktop.
var API = function () {
};
API.prototype.login = function(username, password) {
console.log("request username and pw to server...");
this.auth_token = "nhonhonho";
};
API.prototype.getUserById = function(user_id) {
if (this.auth_token){
console.log("request user with id " + user_id + " with token " + this.auth_token);
return { username: 'Bernardo', email: 'bersimoes' }
}else{
console.log("you need to login first");
}
};
var my_api = new API();
my_api.getUserById('1234');
my_api.login('bernardo', 'password');
my_api.getUserById('1234');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment