检测JavaScript对象是否是FormData实例

时间:2017-09-11 00:02:00

标签: javascript

我一直在寻找一种检查对象是否是FormData实例的方法,类似于Array.isArray()

编辑:如果有人知道instanceof,他们显然不需要指向instanceof。显然不是重复。

1 个答案:

答案 0 :(得分:7)

使用instanceof

例如:

let formData = new FormData()
let time = new Date()

console.log("statement: formData is a FormData instance", formData instanceof FormData) // statement is true
console.log("statement: time is a FormData instance", time instanceof FormData) // statment is false

Source