I have a function that manipulates an object that contains an "upload" member that is of type File. I would like to detect that fact so that I can ignore it and skip over all objects of this type.
I tried a bunch of things in the console, but nothing seems to return "true". Here's a transcript of my futile attempts from inside a console breakpoint:
> 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
Clearly I lack a fundamental understanding of how native types and prototypes work in Javascript.
You can check it using instanceof
keyword.
if (values.avatar.upload instanceof File)
// yes, it's a File type.
else
// no, it's not.
check
values.avatar.upload instanceof File
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With