我有简单的类(使用Dojo):
define ["dojo/request", "dojo/html", "dojo/on", "dojo/dom"], (request, html, observe, dom) ->
class Foo
constructor: (@a) ->
alert @a
我在不同的文件中创建了这个类的新对象:
require ["Libraries/Foo", "dojo/domReady!"], (Foo) ->
t = new Foo "test"
当我将Foo类文件编译成JS时,一切都没有问题,但是当我用例如http://jscompress.com代码缩小JS输出时,代码就会崩溃。
缩小代码后的代码如下:
// Generated by CoffeeScript 1.4.0
(function(){define(["dojo/request","dojo/html","dojo/on","dojo/dom"],function(e,t,n,r){var i;return i=function(){function e(e){this.a=e;alert(this.a)}return e}()})}).call(this);
在控制台(Safari,Chrome)上,我可以看到:
TypeError: '[object Object]' is not a constructor (evaluating 'new Foo("test")')
但是当我在IDE中使用工具重新格式化代码时,一切正常。
改革后的代码:
// Generated by CoffeeScript 1.4.0
(function () {
define(["dojo/request", "dojo/html", "dojo/on", "dojo/dom"], function (e, t, n, r) {
var i;
return i = function () {
function e(e) {
this.a = e;
alert(this.a)
}
return e
}()
})
}).call(this);
请问哪里有问题?
答案 0 :(得分:0)
问题解决了!在Dojo配置中使用async: true
。