Помогите, пожалуйста, понять почему после преобразования каждого элемента массива в цикле результат содержит элемент undefined
здесь http://jsfiddle.net/umEeG/
в методе colorize я преобразую массив и вывожу его через alert
. Первое значение как ни странно Undefined
. Хотелось бы понять откуда оно появилось
(function($){
// -------------------------------------------------------------------------------------------------- options ----------
$.fn.kalininRainbowText = function(options) {
var options = jQuery.extend({
colorArray: new Array('#974bff', '#ec11a1', 'navy', 'orange', '#ecb111', 'magenta', '#055d12', '#4bb1ff')
},options);
return this.each(function() {
// ------------------------------------------------------------------------------------------ properties ---------
var self = $(this);
var colorArrayLength = options.colorArray.length,
text = self.text(),
textLength = text.length;
init();
// ------------------------------------------------------------------------------------------ methods ------------
function init(){
var i,
letterArray = new Array();
for(i = 0; i < textLength; i++){
letterArray[i] = text[i];
}
colorize(i, letterArray);
}
function colorize(textLength, letterArray){
var i,
newText;
for(i = 0; i < textLength; i++){
q = letterArray[i];
letterArray[i] = '<span>' + q + '</span>';
newText += letterArray[i];
}
console.log(newText);
}
function deColorize(){
}
// ------------------------------------------------------------------------------------------ handlers -----------
function onClick(){
alert(1);
}
// ------------------------------------------------------------------------------------------ events -------------
self.on('click', onClick);
});
};
})(jQuery);