Monday, June 3, 2024
34
rated 0 times [  38] [ 4]  / answers: 1 / hits: 34877  / 13 Years ago, wed, june 1, 2011, 12:00:00

I'm trying to convert a function from Javascript to CoffeeScript. This is the code:



function convert(num1, num2, num3) {
return num1 + num2 * num3;
}


But how I can do that in CoffeeScript?






I'm trying to run the function from an HTML source like this:



<script type=text/javascript src=../coffee/convert.js></script>

<script type=text/javascript>
convert(6, 3, 10);
</script>


But it won't work and I get an error saying: ReferenceError: Can't find variable: convert



How to correct this?


More From » coffeescript

 Answers
40

You need to export the convert function to the global scope.

See How can Coffescript access functions from other assets?



window.convert = (num1, num2, num3) ->
num1 + num2 * num3

[#91919] Tuesday, May 31, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
lewis

Total Points: 739
Total Questions: 100
Total Answers: 94

Location: Nepal
Member since Mon, Jan 4, 2021
3 Years ago
lewis questions
Tue, May 11, 21, 00:00, 3 Years ago
Fri, Jul 10, 20, 00:00, 4 Years ago
Wed, May 27, 20, 00:00, 4 Years ago
Thu, Apr 23, 20, 00:00, 4 Years ago
;