mootools/mootools-core — Issue #2321: Calling slice() on number
Author: Xirt
Created: 2012-03-03 14:07:53+00:00
State: open

With the new MooTools 1.4.4 (with no backwards compatibility) I suddenly got the following error (tested in FireFox):

Error: from.slice is not a function
Source File: http://www.mydomain.com/test/js/src/mootools.js
Line: 4747

Some experimenting showed that a number is returned if the variable 'property' is set to 'opacity' on line 4744. An easy (but ugly fix) on this line seems to solve the problem for the mentioned method:

```JavaScript
prepare: function(element, property, values){
values = Array.from(values);
var from = values[0], to = values[1];
if (to == null){
to = from;
from = element.getStyle(property) + ''; // Added empty char to convert to String
var unit = this.options.unit;
// adapted from: https://github.com/ryanmorr/fx/blob/master/fx.js#L299
if (unit && from.slice(-unit.length) != unit && parseFloat(from) != 0){
element.setStyle(property, to + unit);
var value = element.getComputedStyle(property);
// IE and Opera support pixelLeft or pixelWidth
if (!(/px$/.test(value))){
value = element.style[('pixel-' + property).camelCase()];
if (value == null){
// adapted from Dean Edwards' http://erik.eae.net/archives/2007/07/27/18.54.15/#comment-102291
var left = element.style.left;
element.style.left = to + unit;
value = element.style.pixelLeft;
element.style.left = left;
}
}
from = (to || 1) / (parseFloat(value) || 1) * (parseFloat(from) || 0);
element.setStyle(property, from + unit);
}
}
return {from: this.parse(from), to: this.parse(to)};
},
```