Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow view.el to be provided as a function. #1693

Merged
merged 1 commit into from
Oct 2, 2012
Merged

Allow view.el to be provided as a function. #1693

merged 1 commit into from
Oct 2, 2012

Conversation

braddunbar
Copy link
Collaborator

I find this to be a rather elegant way to include the view element in a template (a much requested feature).

var View = Backbone.View.extend({
  el: _.template("<a class='…'><%- this.model.get('name') %></a>")
});

@jashkenas
Copy link
Owner

Cute. You think the implicit-ish this is a good idea for the API?

@braddunbar
Copy link
Collaborator Author

Well, the view is already used as context for id, attributes, className, etc., so I think it's consistent. Further, I think it's in line with the way templates are often used.

render: function() {
  // Uses the view as context.
  this.$el(this.template({...}));
  return this;
}

jashkenas added a commit that referenced this pull request Oct 2, 2012
Allow view.el to be provided as a function.
@jashkenas jashkenas merged commit 84039f3 into jashkenas:master Oct 2, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants