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

Fix #1228 - tagName can be provided as a function. #1234

Merged
merged 1 commit into from Apr 17, 2012
Merged

Fix #1228 - tagName can be provided as a function. #1234

merged 1 commit into from Apr 17, 2012

Conversation

braddunbar
Copy link
Collaborator

No description provided.

@jashkenas
Copy link
Owner

Why would we do this just for tagName, and not className and the rest?

@braddunbar
Copy link
Collaborator Author

className and attributes can already be provided as a function I believe (although only by virtue of jQuery, which doesn't use the view as context). Are there any others I'm missing (maybe id)? I suppose it would be nice to get the correct context with them as well. Perhaps we're overreaching here?

@jashkenas
Copy link
Owner

Out of curiosity, did you actually need this for your app ... or did it just seem like a good idea?

@braddunbar
Copy link
Collaborator Author

This request was submitted as a result of #1228. However, I have needed this before. What I did instead is to pass in the tag name before constructing the view, which is not great for encapsulation, or do the configuration in the constructor, which is less clear IMO.

As a contrived example:

var View = Backbone.View.extend({...});
...
if (options.p) options.tagName = 'p';
new View(options);

as opposed to

var View = Backbone.View.extend({
  tagName: function() {
    return this.options.p ? 'p' : 'div';
  },
  ...
});
...
new View(options);

@randallb
Copy link

I do need this for my app. I'm dynamically constructing "layers" (think photoshop) which can be different types. The example above here is precisely correct.

jashkenas added a commit that referenced this pull request Apr 17, 2012
Fix #1228 - tagName can be provided as a function.
@jashkenas jashkenas merged commit 9c08141 into jashkenas:master Apr 17, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants