Wednesday, 7 June 2017

TypeError: Cannot read property 'prototype' of undefined

I have an issue that I can't seem to resolve, mostly because I have little knowledge of why it is occurring in this particular scenario. Here's the error :

TypeError: Cannot read property 'followers' of undefined
    at Object.<anonymous> (C:\Users\username\Documents\My Lib\bot\src\bot.js:15:4)
    at Module._compile (module.js:570:32)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)
    at Module.runMain (module.js:604:10)
    at run (bootstrap_node.js:393:7)
    at startup (bootstrap_node.js:150:9)
    at bootstrap_node.js:508:3

and here's what the code looks like :

const Twit = require('twit'),
    config = require('./config'),
    init = new Twit(config);

function Twitter(twitter) {
    this.twitter = twitter
}

Twitter.prototype.followers = function(params) {
    this.twitter.get('followers/list', params, (err, data) => {
        if (!err) 
            data.users.forEach(user => console.log(data))
    })
};

var bot = Twitter(init);

bot.followers({ screen_name: 'myscreenname'})

Haha. I'm almost certain it's a silly mistake. I just can't seem to find the source. Any help is and will be appreciated.



via m8r1x

No comments:

Post a Comment