8000 _.template incompatibility with Underscore.js · Issue #16 · lodash/lodash · GitHub
[go: up one dir, main page]

Skip to content

_.template incompatibility with Underscore.js #16

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

Closed
thorlarholm opened this issue May 29, 2012 · 5 comments
Closed

_.template incompatibility with Underscore.js #16

thorlarholm opened this issue May 29, 2012 · 5 comments

Comments

@thorlarholm
Copy link

Underscore.js defines a default variable called 'obj' for use in referencing your JS data from your HTML templates (see https://github.com/documentcloud/underscore/blob/master/underscore.js#L1027).

lodash will read the default data variable name from lodash.templateSettings.variable, which does not exist - just like in Underscore.js.

lodash fails if an underscore template use 'obj' without explicitly setting the variable name to 'obj' in the call to _.template.

This breaks the "drop-in replacement" requirement.

@jdalton
Copy link
Member
jdalton commented May 29, 2012

lodash.templateSettings.variable does exist by default and is object.
https://github.com/bestiejs/lodash/blob/29d67375ba4e8e3b1a622a152e878f7e79c6dc9e/lodash.js#L172-179

I renamed it object to better match Lo-Dash's coding style, but as I don't mention it up front and it doesn't fall into the non-es5 complaint note I will change it.

@jdalton
Copy link
Member
jdalton commented May 29, 2012

I'm curious did you run into this in your code or were you just scanning Lo-Dash's source?

@thorlarholm
Copy link
Author

You are right, it does exist and is called 'object' instead of 'obj'.

I did indeed run into this in my code, which is why I forked and made a change.

@jdalton
Copy link
Member
jdalton commented May 29, 2012

I did indeed run into this in my code, which is why I forked and made a change.

Cool, that let's me know it's not just some super edge case, it's fixed now :D

jdalton added a commit that referenced this issue Aug 29, 2013
…r Underscore.js compatibility. [closes #16]

Former-commit-id: 803d66b
jdalton added a commit that referenced this issue Sep 25, 2014
…r Underscore.js compatibility. [closes #16]

Former-commit-id: da91e5c881e6b3f9e2108cc231e57c023884b251
@lock
Copy link
lock bot commented Jan 21, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Jan 21, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Development

No branches or pull requests

2 participants
0