Created
May 2, 2012 11:59
-
-
Save kimjoar/2576091 to your computer and use it in GitHub Desktop.
An example of a view
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
| // a view constructor which accepts: | |
| // - el, which is a jQuery object of the HTML element the view owns | |
| // - user, which is a user model with key-value pairs | |
| var UserView = function(el, user) { | |
| this.el = el; | |
| this.user = user; | |
| } | |
| UserView.prototype.showImage = function() { | |
| this.el.append('<img src="' + user.image + '" />'); | |
| } | |
| // let's just create a super simple user object | |
| var user = { | |
| image: 'http://example.com/image.png' | |
| }; | |
| // initialize the view with the jQuery object the view owns and a user | |
| var view = new UserView($('.user'), user); | |
| // ... and now we can do stuff which changes the DOM | |
| view.showImage(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment