The source code shown on the Twitch API is correct and functions properly.
“player” is a variable that is hooked to the object in the DOM. Unless player is in the scope you’re trying to use it, you won’t be able to access the variable. You can read more about variables in Javascript at https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/var