Javascript 前缀操作中的左侧表达式无效

Javascript 前缀操作中的左侧表达式无效,javascript,Javascript,我有一个javascript,它应该在点击按钮时创建指向文本文件的下载链接,但是我得到了一个“无效的左侧表达式”错误 js如下所示: (function () { var textFile = null, var makeTextFile = function (text) { var data = new Blob([text], {type: 'text/plain'}); // If we are replacing a previously generated

我有一个javascript,它应该在点击按钮时创建指向文本文件的下载链接,但是我得到了一个“无效的左侧表达式”错误

js如下所示:

(function () {
  var textFile = null,
  var makeTextFile = function (text) {
    var data = new Blob([text], {type: 'text/plain'});

    // If we are replacing a previously generated file we need to
    // manually revoke the object URL to avoid memory leaks.
    if (textFile !== null) {
      window.URL.revokeObjectURL(textFile);
    }

    textFile = window.URL.createObjectURL(data);
    return textFile;
  };

  var create = document.getElementById('create');

  create.addEventListener('click', function () {
    var link = document.getElementById('downloadlink');
    link.href = makeTextFile({{request_string}});
    link.style.display = 'block';
  }, false);
})();
----------------Request File Generated 2015-06-30 17:23:16.324439------------------
     WINDOW_START    |      WINDOW_END     |       DURATION      |         SAT         |         TYPE        |       PRIORITY      |             
--------------------------------------------------------------------------------
 2015/01/02 00:00:00 | 2015/01/22 00:00:00 |         500         |          F7         |       NOMINAL       |          5          |  
<div class="panel panel-body">
      <button id="create">Create file</button> 
      <a download="info.txt" id="downloadlink" style="display: none">Download</a>
</div>
我也尝试过这样做:

var text_string = {{request_string}}
link.href = makeTextFile(text_string);
其中
{{request\u string}}
如下所示:

(function () {
  var textFile = null,
  var makeTextFile = function (text) {
    var data = new Blob([text], {type: 'text/plain'});

    // If we are replacing a previously generated file we need to
    // manually revoke the object URL to avoid memory leaks.
    if (textFile !== null) {
      window.URL.revokeObjectURL(textFile);
    }

    textFile = window.URL.createObjectURL(data);
    return textFile;
  };

  var create = document.getElementById('create');

  create.addEventListener('click', function () {
    var link = document.getElementById('downloadlink');
    link.href = makeTextFile({{request_string}});
    link.style.display = 'block';
  }, false);
})();
----------------Request File Generated 2015-06-30 17:23:16.324439------------------
     WINDOW_START    |      WINDOW_END     |       DURATION      |         SAT         |         TYPE        |       PRIORITY      |             
--------------------------------------------------------------------------------
 2015/01/02 00:00:00 | 2015/01/22 00:00:00 |         500         |          F7         |       NOMINAL       |          5          |  
<div class="panel panel-body">
      <button id="create">Create file</button> 
      <a download="info.txt" id="downloadlink" style="display: none">Download</a>
</div>
html如下所示:

(function () {
  var textFile = null,
  var makeTextFile = function (text) {
    var data = new Blob([text], {type: 'text/plain'});

    // If we are replacing a previously generated file we need to
    // manually revoke the object URL to avoid memory leaks.
    if (textFile !== null) {
      window.URL.revokeObjectURL(textFile);
    }

    textFile = window.URL.createObjectURL(data);
    return textFile;
  };

  var create = document.getElementById('create');

  create.addEventListener('click', function () {
    var link = document.getElementById('downloadlink');
    link.href = makeTextFile({{request_string}});
    link.style.display = 'block';
  }, false);
})();
----------------Request File Generated 2015-06-30 17:23:16.324439------------------
     WINDOW_START    |      WINDOW_END     |       DURATION      |         SAT         |         TYPE        |       PRIORITY      |             
--------------------------------------------------------------------------------
 2015/01/02 00:00:00 | 2015/01/22 00:00:00 |         500         |          F7         |       NOMINAL       |          5          |  
<div class="panel panel-body">
      <button id="create">Create file</button> 
      <a download="info.txt" id="downloadlink" style="display: none">Download</a>
</div>

创建文件
下载
{{request\u string}}
是str类型,所以我不确定问题出在哪里。谁能告诉我我做错了什么


谢谢

我最终使用了
document.getElementsByTagName('pre')
而不是试图传入一个包含字符串的变量。

是否将
{request\u string}}
扩展为包含正确引号的内容?如果没有,您可能有无效的JavaScript。错误消息是否未链接到特定的代码行?您是什么意思,“
{{request\u string}
看起来像这样”?它来自哪里?您是在脚本文件上使用模板引擎还是什么?如果是这样的话,那是哪一个呢?看起来像是使用了一个模板引擎,就像@Bergi所说的,所以你需要引用它:
link.href=makeTextFile(“{request_string}”)@klwahl:这可能与