未捕获的TypeError:非法构造函数 - 在Backbone.JS中使用Bonsai.JS

时间:2013-04-25 21:49:16

标签: javascript backbone.js bonsaijs

我还是js的新手,我正在尝试将bonsai.js放入骨干应用程序中。

我在这里关注此指南:https://github.com/iamdustan/bonsai-demos,并尝试将动画分成一个标题为hero-animation.js的单独文件中的“将事情分开”,但我得到了Uncaught TypeError: Illegal constructor hero-animation.js

的第一行

这在我的Backbone路由器中调用,并且工作正常......

homeAnimation: function() {
    bonsai.run(document.getElementById('heroContent'), {
    url: 'hero-animation.js',
    width: 500,
    height: 400
  });
}

以下是我在hero-animation.js中的内容,它导致第1行出错:

var rect = new Rect(0, 0, 200, 200);
rect
.fill('random')
.addTo(stage)
.attr({
  x: stage.width - rect.attr('width'),
  y: stage.width - rect.attr('height')
})
.animate('0.5s', {
  x: 0,
  y: 0
});

1 个答案:

答案 0 :(得分:5)

好像忘了加入bonsai.js

最初,Rectan "interface",这意味着它不能用作构造函数,而Bonsai会为了自己的目的而覆盖它。