Question

I'm kind of a noobie in javascript, and when i try to use prototypes to extend my object, i get the following error code :

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

Here is my code. I execute this code in nodejs.

The code

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();
Was it helpful?

Solution

In your code sample, you're calling startBrowsing like it's a static method on your constructor function ProcessManager.

Methods added to the prototype of a constructor function are available as methods on instances. You should be calling startBrowsing on your instance of ProcessManager:

var processManager = new ProcessManager();
processManager.startBrowsing();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top