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

Cannot access globals from functions #36

Closed
adamhalasz opened this issue Sep 15, 2013 · 2 comments
Closed

Cannot access globals from functions #36

adamhalasz opened this issue Sep 15, 2013 · 2 comments

Comments

@adamhalasz
Copy link

I'm trying access the global scope from this function:

// js
<% write = (input) -> %>
    <div class="translated"><%- @translate input %></div>
<% end %>

<%- write 'hello' %>


// data
{
    translate: function(input){ return: 'hello world' }
}

but I get this Error:

Cannot call method 'translate' of undefined in page on line 2
@baryshev
Copy link
Owner

You can manually pass this object to custom function if it really needed:

<%- write.call @, 'hello' %>

ECT doesn't change the behavior of inline created functions by default.

@baryshev
Copy link
Owner

baryshev commented Nov 6, 2015

There is another, more beautiful way, to save this context:

<% write = (input) => %>
    <div class="translated"><%- @translate input %></div>
<% end %>

<%- write 'hello' %>

Use => instead of ->

@baryshev baryshev closed this as completed Nov 6, 2015
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

No branches or pull requests

2 participants