Created
January 30, 2019 18:32
-
-
Save burnjohn/ae6935ef475e1ba487c1d7bb8a8f9370 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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