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

JavaScript functions not applied to top level function 11ty.js templates using an arrow function #934

Closed
zachleat opened this issue Feb 14, 2020 · 6 comments
Assignees

Comments

@zachleat
Copy link
Member

zachleat commented Feb 14, 2020

Works:

module.exports = function({ name }) {
  return `<p>${this.upper(name)}</p>`;
};

Broken:

module.exports = ({ name }) => {
  return `<p>${this.upper(name)}</p>`;
};

Can’t find this.upper.

@zachleat zachleat added this to the Next Minor Version milestone Feb 14, 2020
@zachleat zachleat self-assigned this Feb 14, 2020
@zachleat zachleat removed this from the Next Minor Version milestone Feb 14, 2020
@zachleat
Copy link
Member Author

Agree with myself from 30 minutes ago that this is pretty confusing but also it is correct JavaScript behavior, specifically with this and arrow functions. I’ll leave this open as we may have a nicer solution later. Definitely need to add docs around this.

zachleat added a commit that referenced this issue Feb 14, 2020
zachleat added a commit to 11ty/11ty-website that referenced this issue Feb 14, 2020
@pdehaan
Copy link
Contributor

pdehaan commented Feb 14, 2020

Re: original comment... both snippets look the same to me.
Was one of them supposed to use the function syntax, or am I missing something?

@zachleat
Copy link
Member Author

zachleat commented Feb 14, 2020

@pdehaan Ah, yep sorry—edited now!

@zachleat
Copy link
Member Author

zachleat added a commit that referenced this issue Feb 17, 2020
@zachleat
Copy link
Member Author

Closing this as a documentation/education issue. I don’t think there is a good way forward here to smooth this over. Sorry, past me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants