IDL定义
Document#onvisibilitychange
是
attribute EventHandler onvisibilitychange;
EventHandler
其本身被定义为
[LegacyTreatNonObjectAsNull]
callback EventHandlerNonNull = any (Event event);
typedef EventHandlerNonNull? EventHandler;
在哪里?
LegacyTreatNonObjectAsNull
是:
如果[
LegacyTreatNonObjectAsNull
]
extended attribute
出现在a
callback function
,则表示分配给
attribute
其类型为
nullable
回调函数
将被更宽松地转换:如果值不是对象,它将被转换为null,如果值不是
callable
,它将被转换为
回调函数
值在调用时什么也不做。
这里的值不是对象,因此它被视为
null
。不会抛出错误。
其他更严格的属性会抛出,例如
<input>
s
files
attribute
,其定义为
attribute FileList? files;
如果你把它设置成除了a之外的任何东西,它都会扔
FileList
对象:
document.querySelector("input").files = 0;
<input>