<legend id='GmKIG'><style id='GmKIG'><dir id='GmKIG'><q id='GmKIG'></q></dir></style></legend>

  • <tfoot id='GmKIG'></tfoot>
      <bdo id='GmKIG'></bdo><ul id='GmKIG'></ul>

    1. <i id='GmKIG'><tr id='GmKIG'><dt id='GmKIG'><q id='GmKIG'><span id='GmKIG'><b id='GmKIG'><form id='GmKIG'><ins id='GmKIG'></ins><ul id='GmKIG'></ul><sub id='GmKIG'></sub></form><legend id='GmKIG'></legend><bdo id='GmKIG'><pre id='GmKIG'><center id='GmKIG'></center></pre></bdo></b><th id='GmKIG'></th></span></q></dt></tr></i><div id='GmKIG'><tfoot id='GmKIG'></tfoot><dl id='GmKIG'><fieldset id='GmKIG'></fieldset></dl></div>

      <small id='GmKIG'></small><noframes id='GmKIG'>

      1. Coffeescript 在函数中包装文件

        Coffeescript wrapping files in a function(Coffeescript 在函数中包装文件)
          <bdo id='A3m9Q'></bdo><ul id='A3m9Q'></ul>
            <tfoot id='A3m9Q'></tfoot>
                  <tbody id='A3m9Q'></tbody>

                <legend id='A3m9Q'><style id='A3m9Q'><dir id='A3m9Q'><q id='A3m9Q'></q></dir></style></legend>

                  <small id='A3m9Q'></small><noframes id='A3m9Q'>

                  <i id='A3m9Q'><tr id='A3m9Q'><dt id='A3m9Q'><q id='A3m9Q'><span id='A3m9Q'><b id='A3m9Q'><form id='A3m9Q'><ins id='A3m9Q'></ins><ul id='A3m9Q'></ul><sub id='A3m9Q'></sub></form><legend id='A3m9Q'></legend><bdo id='A3m9Q'><pre id='A3m9Q'><center id='A3m9Q'></center></pre></bdo></b><th id='A3m9Q'></th></span></q></dt></tr></i><div id='A3m9Q'><tfoot id='A3m9Q'></tfoot><dl id='A3m9Q'><fieldset id='A3m9Q'></fieldset></dl></div>

                  本文介绍了Coffeescript 在函数中包装文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  出于某种原因,coffeescript 编译器在编译时将我所有的 .coffee 文件包装在一个函数中.例如,如果我有 test.coffee:

                  The coffeescript compiler is, for some reason, wrapping all of my .coffee files in a function when they are compiled. For example, if I have test.coffee:

                  class TestClass
                      constructor: (@value) ->
                  
                      printValue: () ->
                          alert(@value)
                  
                  printAValue = () -> 
                      test = new TestClass()
                      test.printValue()
                  

                  然后我得到 test.js:

                  then I get test.js:

                  (function() {
                    var TestClass, printAValue;
                    TestClass = (function() {
                      function TestClass(value) {
                        this.value = value;
                      }
                      TestClass.prototype.printValue = function() {
                        return alert(this.value);
                      };
                      return TestClass;
                    })();
                    printAValue = function() {
                      var test;
                      test = new TestClass();
                      return test.printValue();
                    };
                  }).call(this);
                  

                  我的简单 html 文件不适用于此:

                  My simple html file won't work with this:

                  <html>
                      <head>
                          <script src="test.js"></script>
                      </head>
                      <body onload="printAValue()">
                      </body>
                  </html>
                  

                  我以前没有使用过很多 JS,我不会怀疑咖啡编译器,但它应该是这样工作的吗?如何

                  I haven't worked with much JS before, and I wouldn't doubt the coffee compiler, but is the way it should work? How

                  推荐答案

                  永远不要在 HTML 中添加事件监听器.将它们添加到您的 JavaScript 中,最好在您定义事件处理程序的同一范围内.

                  Never add event listeners in HTML. Add them in your JavaScript, preferably in the same scope in which you define the event handler.

                  printAValue = () -> 
                      test = new TestClass()
                      test.printValue()
                  
                  document.body.addEventListener('load', printAValue, false)
                  

                  如果您绝对需要将某些内容导出到全局范围,请导出到窗口对象:

                  If you absolutely need to export something to the global scope, export to the window object:

                  window.printAValue = () -> 
                      test = new TestClass()
                      test.printValue()
                  

                  这篇关于Coffeescript 在函数中包装文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  在开发JS过程中,会经常遇到两个小数相运算的情况,但是运算结果却与预期不同,调试一下发现计算结果竟然有那么长一串尾巴。如下图所示: 产生原因: JavaScript对小数运算会先转成二进制,运算完毕再转回十进制,过程中会有丢失,不过不是所有的小数间运算会
                  问题描述: 在javascript中引用js代码,然后导致反斜杠丢失,发现字符串中的所有\信息丢失。比如在js中引用input type=text onkeyup=value=value.replace(/[^\d]/g,) ,结果导致正则表达式中的\丢失。 问题原因: 该字符串含有\,javascript对字符串进行了转
                  Rails/Javascript: How to inject rails variables into (very) simple javascript(Rails/Javascript:如何将 rails 变量注入(非常)简单的 javascript)
                  quot;Each child in an array should have a unique key propquot; only on first time render of page(“数组中的每个孩子都应该有一个唯一的 key prop仅在第一次呈现页面时)
                  Rails 3.1 ajax:success handling(Rails 3.1 ajax:成功处理)
                  CoffeeScript always returns in anonymous function(CoffeeScript 总是以匿名函数返回)
                1. <i id='aZKYs'><tr id='aZKYs'><dt id='aZKYs'><q id='aZKYs'><span id='aZKYs'><b id='aZKYs'><form id='aZKYs'><ins id='aZKYs'></ins><ul id='aZKYs'></ul><sub id='aZKYs'></sub></form><legend id='aZKYs'></legend><bdo id='aZKYs'><pre id='aZKYs'><center id='aZKYs'></center></pre></bdo></b><th id='aZKYs'></th></span></q></dt></tr></i><div id='aZKYs'><tfoot id='aZKYs'></tfoot><dl id='aZKYs'><fieldset id='aZKYs'></fieldset></dl></div>

                        • <bdo id='aZKYs'></bdo><ul id='aZKYs'></ul>
                        • <legend id='aZKYs'><style id='aZKYs'><dir id='aZKYs'><q id='aZKYs'></q></dir></style></legend>
                              <tbody id='aZKYs'></tbody>

                            <small id='aZKYs'></small><noframes id='aZKYs'>

                            <tfoot id='aZKYs'></tfoot>