0

I have a class which I created static functions in it file1, but when i import it in another file and create a new static function it doesn't work as expected it gives me that my new static function is not a function in file3, How can i fix this? Here's my code:

//file1

class Qbs {
  static getRfreshToken(selectors = {}, projection = {}) {
    return QuickBoooks.findOne(selectors, projection);
  }

  static updateRefreshToken(tokenId, tokenValue) {
    return QuickBoooks.update(tokenId, { $set: { refreshToken: tokenValue } });
  }
}

export default Qbs;
}


//file2
const Qbs = require('./index');

module.exports = function () {
    Qbs.prototype.sayMyName = function () {
        return 'zeyad';
    };
};


//file3
import Qbs from './file1'
console.log(Qbs.sayMyName()); //sayMyName is not a function

Zeyad Etman
  • 2,250
  • 5
  • 25
  • 42
  • This post should be tagged with react.js, node.js and whatever else might be appropriate as this is not pure JavaScript and you may get more relevant eyes on the issue. – daddygames Jul 25 '19 at 18:12
  • 2
    @daddygames Why? `static` functions are part of core JavaScript. I also don't see react code in this question. – zero298 Jul 25 '19 at 18:14
  • 1
    I added a new tag `nodejs` @daddygames – Zeyad Etman Jul 25 '19 at 18:14
  • @zero298 it's not a big deal, but this whole thing is based on an understanding of NodeJS and so using the tag will make sure people who are watching that tag see it and can better help address the issue. – daddygames Jul 25 '19 at 18:17
  • Uh, `Qbs.prototype.sayName = …` does not define a static function?! – Bergi Jul 25 '19 at 18:57
  • Also you are never calling the function that is exported from `file2`, so it doesn't do its modifications… – Bergi Jul 25 '19 at 18:58
  • [You should never use a `class` of only static methods](https://stackoverflow.com/q/29893591/1048572) – Bergi Jul 25 '19 at 18:58

1 Answers1

0

In file2 you export a function that modifies the Qbs prototype, but you never import file2, or run that function.

//file3
import Qbs from './file1'
import addSayMyName from './file2'

addSayMyName()
console.log(Qbs.sayMyName()); //sayMyName is not a function
Alex Wayne
  • 178,991
  • 47
  • 309
  • 337