javascript 未捕获的类型错误:非法构造函数 – 在 Backbone.JS 中使用 Bonsai.JS
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16225330/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Uncaught TypeError: Illegal constructor – Using Bonsai.JS in Backbone.JS
提问by ac360
I'm still new to js and I'm trying to fit bonsai.js into a backbone app.
我还是 js 的新手,我正在尝试将 bonsai.js 放入一个主干应用程序中。
I'm following this guide here: https://github.com/iamdustan/bonsai-demos, and trying to 'Separate Things Out' by putting the animation into a separate file titled hero-animation.js
, but I get an Uncaught TypeError: Illegal constructor
on the first line of hero-animation.js
我在这里遵循本指南:https: //github.com/iamdustan/bonsai-demos,并尝试通过将动画放入名为 的单独文件来“分离事物” hero-animation.js
,但我Uncaught TypeError: Illegal constructor
在第一行得到hero-animation.js
This is called in my Backbone router, and is working fine...
这在我的骨干路由器中被调用,并且工作正常......
homeAnimation: function() {
bonsai.run(document.getElementById('heroContent'), {
url: 'hero-animation.js',
width: 500,
height: 400
});
}
Here is what I have in hero-animation.js which is resulting in an error on line 1:
这是我在 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
});
采纳答案by Pavlo
Seems like you forgot to include bonsai.js
.
好像你忘了包括bonsai.js
.
Initially, Rect
is an "interface", which means it can't be used as a constructor, and Bonsai overrides it for its own purposes.
最初,Rect
是一个“接口”,这意味着它不能用作构造函数,并且 Bonsai 出于自己的目的覆盖它。