javascript - `this` object in require().function() -
dealing robots node library, noticed that
var robots = new require('robots').robotsparser(); differs from
var robots = new (require('robots')).robotsparser(); the first require fails lamenting this.somefunction() doesn't exist, while second succeeds. reason, this object in first line above apparently refers global object, while in second line it's bound robots module. why?
the error receive is:
/home/user/crawler/lib/robots/lib/parser.js:44 this.seturl(url, after_parse); ^ typeerror: object #<object> has no method 'seturl' seturl actual somefunction mentioned in example.
var robots = new require('robots').robotsparser(); is parsed as
var robots = (new require('robots')).robotsparser(); i.e. tries call robotsparser method of require() instance. not wanted!
Comments
Post a Comment