2011-05-27 79 views

回答

4

要模擬javascript中的「class-concept」,我們有3 ways。其中一種方法是使用原型功能。 Apple類示例:

function Apple (type) { 
    this.type = type; 
    this.color = "red"; 
} 

Apple.prototype.getInfo = function() { 
    return this.color + ' ' + this.type + ' apple'; 
}; 

在您的示例中,PostProvider函數沒有屬性。所以, 「cmarin」 聲明一個空函數:

PostProvider = function() {}; 

,並添加一些方法:

  • PostProvider.prototype.findAll
  • PostProvider.prototype.findById