Dealing with the robots node library, I noticed that
var robots = new require('robots').RobotsParser();
differs from
var robots = new (require('robots')).RobotsParser();
The first require fails lamenting that a this.someFunction() doesn't exist, while the second succeeds.
For some reason, the this object in the first line above apparently refers to the global object, while in the second line it's bound to the robots module. Why?
The error I receive is:
/home/user/crawler/lib/robots/lib/parser.js:44
this.setUrl(url, after_parse);
^
TypeError: Object #<Object> has no method 'setUrl'
setUrl is the actual someFunction mentioned in the example.