2011-09-23 48 views
0

這是JavaScript代碼來調用 功能警報是從的Stage6,我將完全重建,使其回到居住:)我可以如何調用Javascript原型函數?

// Alerts (in the header) 
    function Alerts(total) { 
     this.current_page = 1; 
     this.last_page = Math.ceil(total/4); 
     if (this.current_page == this.last_page) { 
      $('alert-next-button').className = 'alert-next-inactive'; 
     } 
    } 

這是原型函數是從的DivX的Stage6:

Alerts.prototype.next = function() { 
    if (this.current_page == this.last_page) { 
     return; 
    } 
    new Effect.BlindUp('alerts-' + this.current_page, { 
     scaleFrom:80, 
     duration:0.4, 
     queue:{ 
      position:'end', 
      scope:'alerts' 
     } 
    }); 
    new Effect.BlindDown('alerts-' + (this.current_page + 1), { 
     scaleTo:80, 
     duration:0.4, 
     queue:{ 
      position:'end', 
      scope:'alerts' 
     } 
    }); 
    this.current_page++; 
    if (this.current_page > 1) { 
     $('alert-prev-button').className = 'alert-prev'; 
    } 
    if (this.current_page == this.last_page) { 
     $('alert-next-button').className = 'alert-next-inactive'; 
    } 
} 

第二架原型機功能:

Alerts.prototype.previous = function() { 
    if (this.current_page == 1) { 
     return; 
    } 
    new Effect.BlindUp('alerts-' + this.current_page, { 
     scaleFrom:80, 
     duration:0.4, 
     queue:{ 
      position:'end', 
      scope:'alerts' 
     } 
    }); 
    new Effect.BlindDown('alerts-' + (this.current_page - 1), { 
     scaleTo:80, 
     duration:0.4, 
     queue:{ 
      position:'end', 
      scope:'alerts' 
     } 
    }); 
    this.current_page--; 
    if (this.current_page == 1) { 
     $('alert-prev-button').className = 'alert-prev-inactive'; 
    } 
    if (this.current_page < this.last_page) { 
     $('alert-next-button').className = 'alert-next'; 
    } 
} 

我需要的HTML代碼此功能。 它是反向工程:=)

這裏是從第6階段 http://img10.imageshack.us/img10/1733/83630697.png

我已測試的所有圖像,但是我沒有解決方案。

希望有人能幫助我。

+0

您認爲在這裏的原型功能是什麼? – JaredPar

+0

請描述你正在嘗試做什麼。你想用方法創建一個函數或持久對象嗎?你對'this'的使用通常與一個對象/方法有關,但是我沒有看到任何這種上下文。如果你只是想要一個函數,那麼你可以把'current_page'和'last_page'改成局部變量,並將它用作一個普通函數。 – jfriend00

+0

難道你說的是Prototype.js而不是原型繼承? –

回答

1

不知道,如果你正試圖定義一個函數原型,或撥打一個:

爲了使原型的功能:

Alerts.prototype.nameYourFunction = function(total) { 
    this.current_page = 1; 
    this.last_page = Math.ceil(total/4); 
    if (this.current_page == this.last_page) { 
     $('alert-next-button').className = 'alert-next-inactive'; 
    } 

}; 

更換nameYourFunction,無論你想叫它

然後你就可以這樣稱呼它:

Alerts.nameYourFunction(2); 

或致電您添加到您的問題之一:

Alerts.next(); 
1

嗯...嗯.... var a = new Alerts(5); a.next() ????