Skip to content

Instantly share code, notes, and snippets.

@burnjohn
Created January 30, 2019 18:32
Show Gist options
  • Save burnjohn/ae6935ef475e1ba487c1d7bb8a8f9370 to your computer and use it in GitHub Desktop.
Save burnjohn/ae6935ef475e1ba487c1d7bb8a8f9370 to your computer and use it in GitHub Desktop.
// example 1
let libraryInstance = null;
const initLibrary = () => {
libraryInstance = {
scrollTo() {
console.log('scrolling');
}
};
class Menu {
constructor(libInstance) {
this.libInstance = libInstance;
}
scrollToElement(element) {
this.libInstance.scrollTo(element);
}
}
const menu = new Menu(libraryInstance);
initLibrary();
// example 2
let libraryInstance = {};
const initLibrary = () => {
libraryInstance.scrollTo = () => {
console.log('scrolling');
}
};
class Menu {
constructor(libInstance) {
this.libInstance = libInstance;
}
scrollToElement(element) {
this.libInstance.scrollTo(element);
}
}
const menu = new Menu(libraryInstance);
initLibrary();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment