Skip to content

Instantly share code, notes, and snippets.

@kimjoar
Created May 2, 2012 11:59
Show Gist options
  • Select an option

  • Save kimjoar/2576091 to your computer and use it in GitHub Desktop.

Select an option

Save kimjoar/2576091 to your computer and use it in GitHub Desktop.
An example of a view
// 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