构造器新的transcrypt



我想通过transcrypt代码获取文件。通常,这是用XMLHTTPRequest完成的。在JavaScript脚本中,新的构造函数用于此。我该如何进行跨越?这是我不工作的代码:

#!/usr/bin/env python
# -*- coding: utf-8 -*-
def read_file():
    xmlhttp=XMLHttpRequest()
    xmlhttp.open('GET', "https://raw.githubusercontent.com/bunkahle/Transcrypt-Examples/master/README.md", False);
    xmlhttp.send()
    console.log(xmlhttp.responseText)

和html:

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <script src="__javascript__/read_file.js"></script>
    <title>Read File</title>
  </head>
  <body>
    <main>
        <h1>Read a file!</h1>
        <p id="p1" class="para1">Read a file!</p>
      <button id="button1" onclick="read_file.read_file()">Click for retrieving text file</button><br><br>
      <p id="demo"></p>
    </main>
  </body>
</html>

您可以使用__new__函数创建本机JavaScript对象:

(请注意,对于不需要实例化Python/TransCrypt类(

#!/usr/bin/env python
# -*- coding: utf-8 -*-
def read_file():
    xmlhttp= __new__ (XMLHttpRequest())
    xmlhttp.open('GET', "https://raw.githubusercontent.com/bunkahle/Transcrypt-Examples/master/README.md", False);
    xmlhttp.send()
    console.log(xmlhttp.responseText)

有关此信息的更多信息,请参见:

http://www.transcrypt.org/docs/html/special_facilities.html#creating-javascript-objects-with-new-new-constructor-call

相关内容

  • 没有找到相关文章

最新更新