【问题标题】:browserify and coffeescript. Export coffeescript class in window浏览器化和咖啡脚本。在窗口中导出咖啡脚本类
【发布时间】:2015-04-22 10:37:51
【问题描述】:
B = require './B.coffee'
class A extends B

window.instanceA = new A
window.A = A

类 A 的实例在窗口中可用,但是

new window.A()

返回错误“无法读取未定义的属性'constructor'”

A = (function(_super) {
      __extends(A, _super);

      function A() {
       return A.__super__.constructor.apply(this, arguments);
      }

      return A

    })(B);

我该如何解决?

【问题讨论】:

  • B 可能没有正确加载,如何调用 browserify?
  • 你试过require './B'吗?
  • 不,B加载成功。我可以在 browserify 中使用 A 类。但我想在browserify之外使用A类。如果我在 browserify 之外将“A”称为“新 A”,则会出现错误。

标签: javascript coffeescript browserify


【解决方案1】:

我不确切知道您为什么要实现这一点,但我相信您可以显式导出 B?

window.B = require './B.coffee'
class A extends window.B

window.instanceA = new A
window.A = A

【讨论】:

    猜你喜欢
    • 2013-01-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-03
    • 1970-01-01
    • 2014-04-27
    • 2011-11-08
    相关资源
    最近更新 更多