Last active
January 22, 2020 09:23
-
-
Save StevenLangbroek/e6d9934fa0389fc0ae2e8361ceec5925 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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