我正在使用Github的开源Able Player
UI是非常基本的,我想知道扩展播放器和覆盖诸如

AblePlayer.prototype.getSvgData = function(button) {...
AblePlayer.prototype.setButtonImages = function() {...


这样我就可以使用自己的图标等。

而不装饰原始的ableplayer.js

最佳答案

最好根据MDN用原型继承最佳实践扩展AblePlayer



(function(){
    const AblePlayer = window.AblePlayer;

    function MyAblePlayer(...args) {
        AblePlayer.call(this, ...args);
    }

    MyAblePlayer.prototype = Object.create(AblePlayer.prototype);
    MyAblePlayer.prototype.constructor = MyAblePlayer;

    /* @override method*/
    MyAblePlayer.prototype.getSvgData = function (...args) {
        // if you need to call super do:
        const superResult = AblePlayer.prototype.getSvgData.call(this, ...args);

        // add your code here

        return superResult; // or return some other result
    }

    // Copy static properties
    Object.assign(MyAblePlayer, AblePlayer)

    // Finally override global reference
    window.AblePlayer = MyAblePlayer;
})();

关于javascript - JavaScript原型(prototype)功能覆盖,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/51527776/

10-11 12:48