连接两组设置

时间:2018-12-09 15:58:06

标签: javascript youtube youtube-api youtube-javascript-api

这里要做的是将 oldSettings newSettings 连接起来。

这里的最后一个可以改进吗,还是可以得到最好的?

是由于以下原因造成的:我被告知写错了。

https://jsfiddle.net/g6oaht8f/23/

function combineSettings(oldSettings, newSettings) {
    const playerVars = Object.assign({}, oldSettings.playerVars, newSettings.playerVars);
    const settings = Object.assign({}, oldSettings, newSettings);
    settings.playerVars = playerVars;
    return settings;
}

为此:

https://jsfiddle.net/g6oaht8f/27/

  function combineSettings(oldSettings, newSettings) {
    const oldPlayerVars = oldSettings.playerVars;
    const newPlayerVars = newSettings.playerVars;
    const settings = Object.assign({}, oldSettings, newSettings);
    const playerVars = Object.assign({}, oldPlayerVars, newPlayerVars);
    settings.playerVars = playerVars;
    return settings;
  }

为此:最后的重现

https://jsfiddle.net/g6oaht8f/28/

  function combineSettings(oldSettings, newSettings) {
        const oldPlayerVars = oldSettings.playerVars;
        const newPlayerVars = newSettings.playerVars;
        const settings = Object.assign({}, oldSettings, newSettings);
        settings.playerVars = Object.assign({}, oldPlayerVars, newPlayerVars);
        return settings;
    }

这最后一个可以改进吗?

oldSettings 指的是“ defaultSettings ”,它们都是从此开始的。

 playerVars: {
            autoplay: 1,
            controls: 1,
            showinfo: 1,
            rel: 0,
            iv_load_policy: 3,
            cc_load_policy: 0,
            fs: 0,
            disablekb: 1,
        },

newSettings 是每个负载播放器中指定的内容。

loadPlayer({
    target: ".jacketc",
    width: 600,
    height: 338,
    start: 200,
    end: 205,
    loop:true
});

0 个答案:

没有答案