2013-04-25 2 views
5

Sono ancora nuovo di js e sto cercando di inserire bonsai.js in un'app backbone.Unchaught TypeError: costruttore illegale - Utilizzo di Bonsai.JS in Backbone.JS

Sto seguendo questa guida qui: https://github.com/iamdustan/bonsai-demos, e cercando di 'cose separate Out' mettendo l'animazione in un file separato dal titolo hero-animation.js, ma ottengo un Uncaught TypeError: Illegal constructor sulla prima riga del hero-animation.js

Questo è chiamato in mio router backbone, e sta lavorando bene ...

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

Ecco quello che ho in eroi-animation.js, che si traduce in un errore sulla linea 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 
}); 
+0

http://stackoverflow.com/questions/9950876/javascript-constructing-objects può aiutarti. – Loamhoof

risposta

5

Sembra che abbia dimenticato di includere bonsai.js.

Inizialmente, Rect è an "interface", il che significa che non può essere utilizzato come costruttore e Bonsai lo sostituisce per i propri scopi.