私はES6を学ぶ上での第一歩を踏み出していますが、今はテンプレートに関するいくつかの問題に直面しています。ES6テンプレートで構文エラーが発生する
JavaScriptは次のようになります。私は、ページをロードする際
'<h1>${makeUpperCase('Hello')} ${name} Developer</h1><p>paragraph comes here</p>';
だから捕捉されないでSyntaxErrorを言って、私のコンソールにエラーを参照してください。
"use strict"
let name = 'John';
function makeUpperCase(word){
return word.toUpperCase();
}
let template = '<h1>${makeUpperCase('Hello')} ${name} Developer</h1><p>paragraph comes here</p>';
document.getElementById('template').innerHTML = template;
それは私の変数が読み込まれていないように思えます。予期しない識別子
私のindex.htmlは次のように簡単です:
<html>
<head>
<meta charset="utf-8">
<title>Learning ES6</title>
</head>
<body>
<header>
<h1 id="heading">Learning ES6</h1>
<p>With Sidney de Sousa</p>
</header>
<div id="container">
<div id="template">
</div>
</div>
<script src="src/main.js"></script>
</body>
</html>
HELLO John Developerという見出しがあるはずです。
あなたは
テンプレートのような'バックチックを使用しても、そう、あなたのコードは次のようになります。 '\'
$ {makeUpperCase( 'こんにちは')} $ {name}のデベロッパー
段落はこちら
\ ';' – Joe