2013-09-28 6 views
0

С учетом следующего JS-кода:Рекурсивный метод с OOJS

+ -------------------------------- ------------- +

this.Element = function() { 

this.twitch = function(e) { 
     $(e).animate({ 
      height: "+=5" 
     }, 1000, function() { 
      $(e).animate({ 
       height: "-=5" 
      }, 1000, function() { 
      }); 
     }); 
    }; 

$(document).ready(function() { 
    var footer = new this.Element(); 
    footer.twitch("#footer"); 
}); 

+ ---------------------------- ----------------- +

Как я могу назвать метод "twitch()" рекурсивно?

спасибо.

ответ

0

Первая ошибка, this имеет в виду JQuery в этом контексте new this.Element();

Зафиксировано:

this.Element = function(return this;) { 

this.Element.prototype.twitch = function(e) { 
var self = this; 
     $(e).animate({ 
      height: "+=5" 
     }, 1000, function() { 
      $(e).animate({ 
       height: "-=5" 
      }, 1000, function() { 
       self.twitch(e); 
      }); 
     }); 
    }; 

var self = this; 
$(document).ready(function() { 
    var footer = new this.Element(); 
    footer.twitch("#footer"); 
}); 
Смежные вопросы