I read a book called "Javascript web application" and it has the following lines of code:
The example below, which includes logic inside views, is something you shouldn’t do:
<div>
<script>
function formatDate(date) {
/* ... */
};
</script>
${ formatDate(this.date) }
</div>
I don't understand what { formatDate(this.date) } means in javascript even in jQuery I have never seen it yet (putting object in jQuery function then I've already seen but the above code is not the case). Could you explain me what the meaning of it? Thank you.
I read a book called "Javascript web application" and it has the following lines of code:
The example below, which includes logic inside views, is something you shouldn’t do:
<div>
<script>
function formatDate(date) {
/* ... */
};
</script>
${ formatDate(this.date) }
</div>
I don't understand what { formatDate(this.date) } means in javascript even in jQuery I have never seen it yet (putting object in jQuery function then I've already seen but the above code is not the case). Could you explain me what the meaning of it? Thank you.
Share Improve this question edited Dec 17, 2012 at 3:40 user149341 asked Dec 17, 2012 at 3:30 Khanh TranKhanh Tran 1,8445 gold badges26 silver badges51 bronze badges 3- 2 It just says it's something you shouldn't do, and to the best of my knowledge, can't do. – Linuxios Commented Dec 17, 2012 at 3:32
-
This is not valid syntax. The call isn't even in the scope of the
<script>
tag so you have no reference to the$ object
as it's attached to thewindow
and the window can only be referencedinline, within script tags, or in a .js document
. – Ohgodwhy Commented Dec 17, 2012 at 3:33 -
2
The
${ }
bit is not Javascript. It looks like it's meant to be part of some template syntax to be expanded by the template processor. – melpomene Commented Dec 17, 2012 at 3:35
2 Answers
Reset to default 7${}
is a Template Tag, used by jQuery Template Plugin.
${} Template Tag
Used for insertion of data values in the rendered template. Evaluates the specified field (property) on the current data item, or the specified JavaScript function or expression.
It's actually a bit more than this: Indeed, the jQuery Template Plugin used to have this syntax ${}
. However, currently, this is part of the ES 6 (aka EcmaScript 2015) standard.
Reference: http://exploringjs./es6/ch_template-literals.html