Say I have the following code.
const myNPMPackage = require("myNPMPackage");
const checkIfUserPackage = require("checkIfUserPackage");
const userObj = {"name": {"first": "Joe", "last": "Smith"}};
const user = new myNPMPackage.User(userObj);
checkIfUserPackage.checkIfUser(user); // true
checkIfUserPackage.checkIfUser(userObj); // false
// Then in the `checkIfUserPackage` package it has the following code, and also has `myNPMPackage` as a dependency of `checkIfUserPackage`
const myNPMPackage = require("myNPMPackage");
module.exports.checkIfUser = (user) => user instanceof myNPMPackage.User;
This code works perfectly and as expected.
My question is, what happens if myNPMPackage makes an update to that User class, and the myNPMPackage version that I'm using in my code is a different version than the myNPMPackage version that checkIfUserPackage is using?
Obviously in that case it's possible that the myNPMPackage.User class will be different in my project than it is in checkIfUserPackage. But I still want that checkIfUser method to return true.
Under the hood, how does instanceof work between NPM package versions?
If this will cause problems across versions, is there any work arounds to ensure that even across different versions that the instanceof will return the expected result?