Answer the question
In order to leave comments, you need to log in
Why does the error "TypeError: newsList is not a function" occur?
newsList = (news_id) ->
alert news_id
return
<script>
newsList(10);
</script>
Answer the question
In order to leave comments, you need to log in
This is because newsList will be declared in the local scope, your code will be wrapped in (function() {...}).call(this);
If you want to use it as in your example, you need to explicitly specify it:
window.newsList = (news_id) ->
alert news_id
return
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question