Check for an instance of ArrayBufferView?

前端 未结 2 2115
被撕碎了的回忆
被撕碎了的回忆 2021-02-15 09:24

Background

With a bit of research I\'ve found that, although ArrayBufferView wasn\'t initially exposed (through [NoInterfaceObject]) there appeared to be

2条回答
  •  攒了一身酷
    2021-02-15 10:09

    I would use either:

    function isAbv(value) {
        return value && value.buffer instanceof ArrayBuffer && value.byteLength !== undefined;
    }
    

    or:

    var ArrayBufferView = Object.getPrototypeOf(Object.getPrototypeOf(new Uint8Array)).constructor;
    function isAbv(value) {
        return value instanceof ArrayBufferView;
    }
    

提交回复
热议问题