问题描述
我很好奇它是如何运作这种结构的。当我从Javascript访问navigator.mimetypes时,我正在访问一个对象。
I'm curious about how it is working this structure. When I'm accesing the navigator.mimetypes from Javascript I'm accesing an object.
>>> typeof(navigator.mimeTypes)
"object"
该对象包含对象列表。
navigator.mimeTypes [Object_0,Object_1,Object_2,...]
navigator.mimeTypes[Object_0, Object_1, Object_2, ...]
>>> typeof(navigator.mimeTypes[0])
"object"
例如,我可以检索第一个对象:
For example, I can retrieve the first object:
MimeType { constructor=MimeType, enabledPlugin=Plugin, type="application/x-vnd.google.update3webcontrol.3"}
任何人都可以解释一下为什么这有效吗?
Can anyone explain me why this is working?
>>> navigator.mimeTypes["application/x-shockwave-flash"]
MimeType { constructor=MimeType, type="application/x-shockwave-flash", description="",more...}
我的意思是为什么我能够通过[application / x-shockwave找到指定的对象-flash] ??
I mean why I am able to find the specified object by means of ["application/x-shockwave-flash"] ??
javascript对我来说将是一个新世界:)
javascript will be a new world to me :)
推荐答案
navigator.mimeTypes
返回一个名为的对象MimeTypeArray
它不是传统的JavaScript数组,而是一个对象有类似数组的属性,你可以通过索引或名称访问它的属性。
navigator.mimeTypes
returns an object called MimeTypeArray
it's not a traditional JavaScript array but an object that had Array like properties, you can access it's properties either by index or name.
编辑:当你使用 navigator.mimeTypes ['someType']
你正在将 MimeTypeArray
视为哈希映射,其中 someType
映射到a MimeType
数组中的对象,该对象还具有与键值相同的类型
属性。这是DOM中的一个奇怪的对象(不是技术上的JavaScript),你通常不会看到很多像这样的对象。
edit: When you use navigator.mimeTypes['someType']
you're treating the MimeTypeArray
like a hash map, that has someType
mapped to a MimeType
object in the array that also has a type
property of the same value as the key. This is a strange object in the DOM (not technically JavaScript) and you don't typically see many objects like this.
这篇关于navigator.mimeTypes结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!