Only tween strings, numbers and arrays.

This commit is contained in:
Jonathan Stanton 2013-07-31 18:11:28 -07:00
parent 29d77a5f53
commit fa2532d356
2 changed files with 46 additions and 1 deletions

View File

@ -285,7 +285,10 @@ TWEEN.Tween = function ( object ) {
end = start + parseFloat(end, 10);
}
_object[ property ] = start + ( end - start ) * value;
// protect against non numeric properties.
if ( typeof(end) === "number" ) {
_object[ property ] = start + ( end - start ) * value;
}
}

View File

@ -83,8 +83,50 @@ test( "Tween non-null property", function() {
});
test( "Tween function property", function() {
var my_function = function() {};
var obj = { x: my_function },
t = new TWEEN.Tween( obj );
t.to( { x: my_function } );
t.start( 0 );
t.update( 1000 );
ok( obj.x === my_function );
});
test( "Tween boolean property", function() {
var obj = { x: true },
t = new TWEEN.Tween( obj );
t.to( { x: function() {} } );
t.start( 0 );
t.update( 1000 );
ok( typeof obj.x === "boolean" );
ok( obj.x );
});
test( "Tween null property", function() {
var obj = { x: null },
t = new TWEEN.Tween( obj );
t.to( { x: 2 }, 1000 );
t.start( 0 );
t.update( 1000 );
deepEqual( obj.x, 2 );
});
test( "Tween undefined property", function() {
var obj = { },
t = new TWEEN.Tween( obj );