美文网首页
解读flvjs源码 第1篇 从/src/flv.js入口,po

解读flvjs源码 第1篇 从/src/flv.js入口,po

作者: Kason晨 | 来源:发表于2020-09-21 10:42 被阅读0次
import Polyfill from './utils/polyfill.js';

// install polyfills
Polyfill.install();

这主要是方式一些旧浏览器没有这些api接口,写的一些兼容性写法。具体写在注释里了。

//./utils/polyfill.js
class Polyfill {

    static install() {
        // ES6 Object.setPrototypeOf
      //判断有没有setPrototypeOf 属性,即是否可以更改原型链上的参数值。如果有则直接赋值,没有就写个兼容性的写法。
        Object.setPrototypeOf = Object.setPrototypeOf || function (obj, proto) {
            obj.__proto__ = proto;
            return obj;
        };

 // ES6 Object.assign
//判断是否支持Object.assign 属性,用以从两个对象中合并属性到目标对象。如果有则直接赋值,没有就写个兼容性的写法。
//相关文档: 
//[https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Object/assign](https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Object/assign)

        Object.assign = Object.assign || function (target) {
            if (target === undefined || target === null) {
                throw new TypeError('Cannot convert undefined or null to object');
            }

            let output = Object(target);
            for (let i = 1; i < arguments.length; i++) {
                let source = arguments[i];
                if (source !== undefined && source !== null) {
                    for (let key in source) {
                        if (source.hasOwnProperty(key)) {
                            output[key] = source[key];
                        }
                    }
                }
            }
            return output;
        };

        // ES6 Promise (missing support in IE11)
//检查是否支持Promise,如果不支持旧引用插件的兼容写法,使其支持。
        if (typeof self.Promise !== 'function') {
            require('es6-promise').polyfill();
        }
    }

}

//这个我感觉是引用了后旧自动执行一次install方法。
Polyfill.install();

export default Polyfill;

相关文章

网友评论

      本文标题:解读flvjs源码 第1篇 从/src/flv.js入口,po

      本文链接:https://www.haomeiwen.com/subject/gvxvyktx.html