请考虑下面的代码示例,并将重点放在变量赋值上。由于我从未在 C++ 中见过这种形式,以下是什么意思:“上传”in new XMLHttpRequest`。
我需要很好地解释以下语句的含义:progress: "upload"in new XMLHttpRequest
。特别是 in
在 C++ 中不存在。 in
应该做什么?
tests = {
filereader: typeof FileReader != 'undefined',
dnd: 'draggable' in document.createElement('span'),
formdata: !!window.FormData,
progress: "upload" in new XMLHttpRequest
};
谢谢。
最佳答案
Chapter 11.8.7 - The in
operator说
Return the result of calling the [[HasProperty]] internal method of rval with argument ToString(lval).
这意味着
(lval in rval)
当 rval
是一个对象并且它有一个名为 String(lval)
的属性时为真。
in
也用在 for (... in ...)
循环中,但这只是类似的语法,而不是使用此运算符。
"upload" in new XMLHttpRequest
这是在询问“XMLHttpRequest
实例是否具有名为‘upload’的属性?”它正在有效地检查此浏览器是否具有可能并非在所有浏览器上都存在的特定功能。
upload
特别在 XMLHttpRequest Level 2 中指定作为 supports certain event handler 的对象让您监控上传进度:
interface XMLHttpRequestEventTarget : EventTarget { // event handlers [TreatNonCallableAsNull] attribute Function? onloadstart; [TreatNonCallableAsNull] attribute Function? onprogress; [TreatNonCallableAsNull] attribute Function? onabort; [TreatNonCallableAsNull] attribute Function? onerror; [TreatNonCallableAsNull] attribute Function? onload; [TreatNonCallableAsNull] attribute Function? ontimeout; [TreatNonCallableAsNull] attribute Function? onloadend; };
关于javascript - JavaScript 中 "in"的解释,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12549352/