我有一个函数,它操作一个包含"upload"成员的对象,该成员的类型为File。我想检测这个事实,以便我可以忽略它并跳过所有这种类型的对象。
我在控制台中尝试了很多方法,但似乎没有返回"true"。以下是我在控制台断点内的一些徒劳无功的尝试记录:
> values.avatar
{upload: File}
> values.avatar.upload
File {name: "29_Drawing Hands by Escher.jpg", lastModified: 1446580115000, lastModifiedDate: Tue Nov 03 2015 14:48:35 GMT-0500 (Eastern Standard Time), webkitRelativePath: "", size: 1314300, …}
> values.avatar.upload.isPrototypeOf(File)
false
> File
ƒ File() { [native code] }
> File.prototype
File {constructor: ƒ, …}
values.avatar.upload.isPrototypeOf(File.prototype)
false
> values.avatar.upload.prototype
undefined
> File.isPrototypeOf
ƒ isPrototypeOf() { [native code] }
> File
ƒ File() { [native code] }
> values.avatar
{upload: File}
> File
ƒ File() { [native code] }
> File.__proto__
ƒ Blob() { [native code] }
> values.avatar.upload.__proto__
File {constructor: ƒ, …}
values.avatar.upload.isPrototypeOf(File.__proto__)
false
> values.avatar.upload.isPrototypeOf(Blob.__proto__)
false
显然我缺乏对JavaScript中原生类型和原型工作方式的基本理解。
values.avatar.upload instanceof File
。 - pushkin