Quantcast
Channel: Active questions tagged youtube-api - Stack Overflow
Viewing all articles
Browse latest Browse all 3720

JavaScript: Create a method in a key in an object if input of the main function exists

$
0
0

I am trying to create a variable Youtube Object that will be simulated in a for loop.

The concept is that I want to set a variable speed to each clip in a for loop. The idea is that YouTube takes in an object as described here. This seems difficult.

I created the function here:

function YTObjects(videoId1, ...args) {  let object1 = {    height: "315",    width: "560",    videoId: videoId1,    playerVars: {      autoplay: 0,      loop: 1,      ...(typeof args[0] !== "undefined" && { start: `${args[0]}` }),      ...(typeof args[1] !== "undefined" && { end: `${args[1]}` }),    },    if ((typeof args[2] !== "undefined") && (typeof args[3] !== "undefined")) {      event: function (args[2], args[3]) {        player.setPlaybackRate(args[2]*args[3]);      },    }  };  return object1;}

Which enables me to create a variable object. But I am failing to create a function in a key that depends on the arguments (2&3).

Can you please help in this regard?


Viewing all articles
Browse latest Browse all 3720

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>