Hopefully, you’ll never need to use it, but if you ever need to intersperse snippets of JavaScript within your CoffeeScript
, you can use backticks
to pass it straight
through.
hi = `function() {
return [document.title, "Hello JavaScript"].join(": ");
}`
​
var hi;
​
hi = function() {
return [document.title, "Hello JavaScript"].join(": ");
};
Escape backticks with backslashes : \`​
becomes `
​.
Escape backslashes before backticks with more backslashes : \\\`
​ becomes \`
​.
markdown = `function () {
return \`In Markdown, write code like \\\`this\\\`\`;
}`
​
var markdown;
​
markdown = function () {
return `In Markdown, write code like \`this\``;
};​
​
You can also embed blocks of JavaScript using triple backticks
. That’s easier than escaping backticks, if you need them inside your JavaScript block.
```
function time() {
return `The time is ${new Date().toLocaleTimeString()}`;
}
```
​
function time() {
return `The time is ${new Date().toLocaleTimeString()}`;
}
;