Adding Const defaultPlayerVars =

To help simplify things I’ve moved the code out to local files, with a different file for each section of code. I now have the following script files:

  • spinner.js
  • manage-cover.js
  • video-player.js
  • add-player.js
  • add-players.js

Separating them like that helps to reveal some structural issues. For example:

  • manage-cover - undeclared videoPlayer
  • video-player - undeclared YT
  • add-player - undeclared videoPlayer and manageCover
  • add-players - undeclared videoPlayer, spinner, and addPlayer

Some of them are best resolved by declaring a global variable at the top of the code, but that’s a last resort. Usually it’s better to find ways to give the desired information instead.

The video-player code is the only one that expects YT. That’s also because when it loads player_api that script creates YT. The approved way according to JSLint is to define a variable:

let YT = undefined;

But, the player_api code refuses to run when it finds that YT already exists, even if it’s undefined, saying: Uncaught SyntaxError: Identifier 'YT' has already been declared

So, a JSLint directive to expect YT as a global variable is required there instead.

/*global YT */
const videoPlayer = (function makeVideoPlayer() {

The other issues are ones that I’ll plug away at in due course.

1 Like