From ba107340703fa07437a44e0d886c4ee094fa4f7b Mon Sep 17 00:00:00 2001 From: sreid Date: Mon, 9 May 2011 09:18:48 -0700 Subject: [PATCH] added embedding_javascript recipe --- chapters/syntax/embedding_javascript.textile | 35 ++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 chapters/syntax/embedding_javascript.textile diff --git a/chapters/syntax/embedding_javascript.textile b/chapters/syntax/embedding_javascript.textile new file mode 100644 index 0000000..ea407d7 --- /dev/null +++ b/chapters/syntax/embedding_javascript.textile @@ -0,0 +1,35 @@ +--- +layout: recipe +title: Embedding JavaScript +chapter: Syntax +--- + +h2. Problem + +You want to include some found/pre-written JavaScript code inline with your CoffeeScript + +h2. Solution + +Wrap the JavaScript with backticks: + +{% highlight coffeescript %} +`function greet(name) { +alert("Hello "+name); +}` + +# Back to CoffeeScript +greet "Coffee" +{% endhighlight %} + +h2. Discussion + +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: + +{% highlight coffeescript %} +hello = `function (name) { +alert("Hello "+name) +}` +hello "Coffee" + +{% endhighlight %} +Here the "hello" variable is still in CoffeeScript, but is assigned a function written in JavaScript. \ No newline at end of file