如何检查变量是否为JavaScript中的Blob [英] How to check if a variable is a blob in JavaScript

查看:2554
本文介绍了如何检查变量是否为JavaScript中的Blob的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

作为typeof返回对象".

As typeof returns "object"..

var MyBlob = new Blob(['test text'], {type : 'text/plain'});
console.log(typeof MyBlob) // "object"

请求通用的解决方案来检查变量是否是blob是否为时过早,因为它尚未得到广泛支持?还是应该在已经实现了浏览器的浏览器中测试Blob类型?

is it too early to ask for a generic solution for checking whether or not a variable is a blob as it is not yet widely supported? Or how should I go about testing for blob type in browsers which already have it implemented?

推荐答案

您可以像这样测试它是否是Blob的实例:

You can test if it is an instanceof Blob like this:

var MyBlob = new Blob(['test text'], {type : 'text/plain'});
console.log(MyBlob instanceof Blob) // true

jsFiddle: http://jsfiddle.net/jfriend00/5xkgd/

jsFiddle: http://jsfiddle.net/jfriend00/5xkgd/

这也适用于从Blob继承的事物.

This will work for things that inherit from Blob also.

这篇关于如何检查变量是否为JavaScript中的Blob的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆