Skip to content

Instantly share code, notes, and snippets.

@StevenLangbroek
Last active January 22, 2020 09:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save StevenLangbroek/e6d9934fa0389fc0ae2e8361ceec5925 to your computer and use it in GitHub Desktop.
Save StevenLangbroek/e6d9934fa0389fc0ae2e8361ceec5925 to your computer and use it in GitHub Desktop.
window.Users = (function Users() {
// private to this "Module"
function User(attrs) {
this.id = attrs.id;
this.name = attrs.name;
};
User.prototype.sayHello = function sayHello () {
console.log("Hey! I'm" + this.name + "! Nice to meet you!");
return this;
}
// public interface
return {
getById: function getById(id, cb) {
// construct XMLHttpRequest and create a new User instance y'all!
// super fun!
}
}
})();
var UserView = Backbone.View.extend({
initialize: function (options) {
Users.getById(options.id, this.setUser.bind(this));
},
setUser: function setUser(user) {
this.user = user;
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment