Note that there are some explanatory texts on larger screens.

plurals
  1. POMeaning of Dollar Sign & Curly Braces Containing Javascript Block Outside of HTML Script Tag
    primarykey
    data
    text
    <p>I'm currently reading <strong>'Javascript Web Applications' (O'Reilly, Alex MacCaw)</strong> and very early on there's a code snippet which might appear to execute a JS function, within an HTML document, yet it is not enclosed by <code>&lt;script&gt;</code> tags:</p> <pre><code>// template.html &lt;div&gt; &lt;script&gt; function doSomething(aParam) { /* do stuff ... */ }; &lt;/script&gt; ${ doSomething(this.someX) } &lt;/div&gt; </code></pre> <p>Please could someone kindly explain the <strong>dollar-sign-curly-brace notation</strong>? I'm currently learning JS and I haven't seen this before, so I'm presuming it's either JS shorthand for code execution (if so, why no terminating semi-colon?), or perhaps some proprietary <strong>templating</strong> mark-up (Ruby? PHP?), or something else entirely?</p> <p>Many thanks.</p> <p><strong>UPDATE</strong></p> <p>It transpires that later on in Chapter 5 (of the aforementioned book) we are then introduced to <strong>Javascript templating</strong>. It appears to be an assumption by the author that the reader has already encountered this templating technique before reading the book. As noted by <strong>Stackoverflow member Esailija</strong>, this book is <strong><em>not</em></strong> a beginners' guide to Javascript; I should add that I'm reading this book in parallel with <strong>'Javascript: The Good Parts' (O'Reilly, Douglas Crockford)</strong> amongst others.</p> <p><em>I had half-suspected some kind of templating, but I hadn't considered pure JS templating. I have used PHP and RoR frameworks in the past which also used similar templating concepts for injecting model data into views.</em></p> <p>One final point: my reason(s) for reading <strong>'Javascript Web Applications'</strong> is that it discusses the Model-View-Controller (MVC) pattern within the JS sphere. While it advocates the use of the <strong>jQuery library</strong> (among others) to both enhance and accelerate development, it is not a <strong><em>jQuery API book</em></strong> or yet-another-new-javascript-wrapper; rather, the book makes use of such libraries (where appropriate) to deal with cross-browser JS inconsistencies, while driving home actual JS best practices and patterns in creating 'web applications'.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload