我有点喜欢javascript,当我尝试使用原型扩展对象时,出现以下错误代码:

Object function ProcessManager() {...} has no method 'startBrowsing'


这是我的代码。我在nodejs中执行此代码。

代码

function ProcessManager(){
    this.browser = new Browser();

    this.salePagesToVisit = [];
    this.salePagesCurrent = [];
    this.salePagesDone = [];

    this.categoryPagesToVisit = [];
    this.categoryPagesCurrent = [];
    this.categoryPagesDone = [];

    this.listPagesToVisit = [];
    this.listPagesCurrent = [];
    this.listPagesDone = [];

}

ProcessManager.prototype.startBrowsing = function () {
    winston.log('verbose', 'Starting scrapping Bazarchic');

}


var processManager = new ProcessManager();
ProcessManager.startBrowsing();

最佳答案

在您的代码示例中,您正在调用startBrowsing,就像它是构造函数ProcessManager上的静态方法一样。

添加到构造函数原型中的方法可用作实例上的方法。您应该在startBrowsing实例上调用ProcessManager

var processManager = new ProcessManager();
processManager.startBrowsing();

09-16 09:55