You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
You want to include some found/pre-written JavaScript code inline with your CoffeeScript
10
+
11
+
h2. Solution
12
+
13
+
Wrap the JavaScript with backticks:
14
+
15
+
{% highlight coffeescript %}
16
+
`function greet(name) {
17
+
alert("Hello "+name);
18
+
}`
19
+
20
+
# Back to CoffeeScript
21
+
greet "Coffee"
22
+
{% endhighlight %}
23
+
24
+
h2. Discussion
25
+
26
+
This is a simple way to integrate small snippets of JavaScript code into your CoffeeScript without converting it over to use CoffeeScript syntax. As shown in the "CoffeeScript Language Reference":http://jashkenas.github.com/coffee-script/#embedded you can mix to the two languages to a certain extent:
27
+
28
+
{% highlight coffeescript %}
29
+
hello = `function (name) {
30
+
alert("Hello "+name)
31
+
}`
32
+
hello "Coffee"
33
+
34
+
{% endhighlight %}
35
+
Here the "hello" variable is still in CoffeeScript, but is assigned a function written in JavaScript.
0 commit comments