3

Object.getOwnPropertyNames(window)不会在返回的数组中返回 setTimeout 值。

这里有什么问题?

之后我想检查 setTimeout 属性的属性描述符对象,但Object.getOwnPropertyDescriptor(window,"setTimeout")返回未定义。

    var windowProp = Object.getOwnPropertyNames(window);

    for(var i=0; i< windowProp.length; i++){
    console.log(windowProp[i]);}
    // i don't see setTimeout in the console output

    Object.getOwnPropertyDescriptor(window,"setTimeout")
    //undefined
4

1 回答 1

2

那是因为setTimeout不在那个名单上。

我看到的(在 Chrome [在此页面上]):

Date
EventEmitter
RegExp
adzerk2_inline_ly45m8gua792qbvm
careers_adselector
moveScroller
Function
encodeURIComponent
TypeError
ados_loadFIframe
_gat
careers_cssurl
PR_SHOULD_USE_CONTINUATION
decodeURIComponent
Number
i
sanitizeAndSplitTags
adFeedbackCastVote
adzerk2_html_rpcn4bbtg94kbrvw
genuwine
ados
Boolean
azScriptExtensionLoad
quantserve
eval
StackExchange
PR
isNaN
Array
styleCode
CTIsPlayback
unescape
external
zshow
tagRendererRaw
cssLinkLoad
apiCallbacks
Markdown
scriptSrc
NaN
escape
RangeError
adzerk2_func_fi5lor1t31ib0xu6
v8Intl
careers_leaderboardcssurl
azInitExtension
Object
EvalError
URIError
_gaq
parseFloat
isFinite
careers_companycssurl
uh
gauth
adzerk2_func_d1qd3ryzl0aanl1m
azScriptSRCLoad
_qevents
document
azLoad
decodeURI
__qc
windowProp
tagRenderer
undefined
prettyPrintOne
azHtmlLoad
azScriptInlineLoad
votesCast
SyntaxError
initFadingHelpText
Generator
showFadingHelpText
careers_adurl
jQuery
Infinity
String
prettyPrint
top
zItems
parseInt
JSON
WinterBash
azRegisterExtension
ReferenceError
cssLoad
Math
profileLink
encodeURI
window
Error
location
prepareEditor
initTagRenderer
gaGlobal
chrome
$
ados_frameLoaded
webkitAudioContext
webkitRTCPeerConnection
webkitMediaStream
WebSocket
webkitNotifications
WebKitSourceBufferList
WebKitSourceBuffer
WebKitMediaSource
SharedWorker
DeviceOrientationEvent
MediaController
HTMLSourceElement
TimeRanges
MediaError
HTMLVideoElement
HTMLMediaElement
HTMLAudioElement
Audio
TrackEvent
TextTrackList
TextTrackCueList
TextTrackCue
TextTrack
HTMLTrackElement
localStorage
sessionStorage
applicationCache
OfflineAudioCompletionEvent
AudioProcessingEvent
webkitAudioPannerNode
MediaStreamEvent
RTCIceCandidate
IceCandidate
RTCSessionDescription
SessionDescription
SQLException
CloseEvent
webkitStorageInfo
webkitIDBTransaction
webkitIDBRequest
webkitIDBObjectStore
webkitIDBKeyRange
webkitIDBIndex
webkitIDBFactory
webkitIDBDatabaseException
webkitIDBDatabase
webkitIDBCursor
webkitIndexedDB
Notification
webkitIntent
WebKitIntent
WebKitMutationObserver
webkitURL
URL
WebKitBlobBuilder
FileReader
FileError
FormData
SVGFilterElement
SVGFETurbulenceElement
SVGFETileElement
SVGFESpotLightElement
SVGFESpecularLightingElement
SVGFEPointLightElement
SVGFEOffsetElement
SVGFEMorphologyElement
SVGFEMergeNodeElement
SVGFEMergeElement
SVGFEImageElement
SVGFEGaussianBlurElement
SVGFEFuncRElement
SVGFEFuncGElement
SVGFEFuncBElement
SVGFEFuncAElement
SVGFEFloodElement
SVGFEDropShadowElement
SVGFEDistantLightElement
SVGFEDisplacementMapElement
SVGFEDiffuseLightingElement
SVGFEConvolveMatrixElement
SVGFECompositeElement
SVGFEComponentTransferElement
SVGFEColorMatrixElement
SVGFEBlendElement
SVGComponentTransferFunctionElement
SVGVKernElement
SVGMissingGlyphElement
SVGHKernElement
SVGGlyphRefElement
SVGGlyphElement
SVGFontFaceUriElement
SVGFontFaceSrcElement
SVGFontFaceNameElement
SVGFontFaceFormatElement
SVGFontFaceElement
SVGFontElement
SVGAltGlyphItemElement
SVGAltGlyphElement
SVGAltGlyphDefElement
SVGSetElement
SVGMPathElement
SVGAnimateTransformElement
SVGAnimateMotionElement
SVGAnimateElement
SVGAnimateColorElement
SVGZoomAndPan
SVGViewSpec
SVGViewElement
SVGUseElement
SVGUnitTypes
SVGTSpanElement
SVGTRefElement
SVGTransformList
SVGTransform
SVGTitleElement
SVGTextPositioningElement
SVGTextPathElement
SVGTextElement
SVGTextContentElement
SVGSymbolElement
SVGSwitchElement
SVGSVGElement
SVGStyleElement
SVGStringList
SVGStopElement
SVGScriptElement
SVGRenderingIntent
SVGRectElement
SVGRect
SVGRadialGradientElement
SVGPreserveAspectRatio
SVGPolylineElement
SVGPolygonElement
SVGPointList
SVGPoint
SVGPatternElement
SVGPathSegMovetoRel
SVGPathSegMovetoAbs
SVGPathSegList
SVGPathSegLinetoVerticalRel
SVGPathSegLinetoVerticalAbs
SVGPathSegLinetoRel
SVGPathSegLinetoHorizontalRel
SVGPathSegLinetoHorizontalAbs
SVGPathSegLinetoAbs
SVGPathSegCurvetoQuadraticSmoothRel
SVGPathSegCurvetoQuadraticSmoothAbs
SVGPathSegCurvetoQuadraticRel
SVGPathSegCurvetoQuadraticAbs
SVGPathSegCurvetoCubicSmoothRel
SVGPathSegCurvetoCubicSmoothAbs
SVGPathSegCurvetoCubicRel
SVGPathSegCurvetoCubicAbs
SVGPathSegClosePath
SVGPathSegArcRel
SVGPathSegArcAbs
SVGPathSeg
SVGPathElement
SVGPaint
SVGNumberList
SVGNumber
SVGMetadataElement
SVGMatrix
SVGMaskElement
SVGMarkerElement
SVGLineElement
SVGLinearGradientElement
SVGLengthList
SVGLength
SVGImageElement
SVGGradientElement
SVGGElement
SVGException
SVGForeignObjectElement
SVGEllipseElement
SVGElementInstanceList
SVGElementInstance
SVGElement
SVGDocument
SVGDescElement
SVGDefsElement
SVGCursorElement
SVGColor
SVGClipPathElement
SVGCircleElement
SVGAnimatedTransformList
SVGAnimatedString
SVGAnimatedRect
SVGAnimatedPreserveAspectRatio
SVGAnimatedNumberList
SVGAnimatedNumber
SVGAnimatedLengthList
SVGAnimatedLength
SVGAnimatedInteger
SVGAnimatedEnumeration
SVGAnimatedBoolean
SVGAnimatedAngle
SVGAngle
SVGAElement
SVGZoomEvent
XPathException
XPathResult
XPathEvaluator
Storage
ClientRectList
ClientRect
MimeTypeArray
MimeType
PluginArray
Plugin
MessageChannel
MessagePort
XSLTProcessor
XMLHttpRequestException
XMLHttpRequestUpload
XMLHttpRequest
XMLSerializer
DOMParser
XMLDocument
EventSource
RangeException
Range
NodeFilter
Blob
FileList
File
Worker
Clipboard
WebKitPoint
WebKitCSSMatrix
WebKitCSSRegionRule
WebKitCSSKeyframesRule
WebKitCSSKeyframeRule
EventException
WebGLContextEvent
SpeechInputEvent
StorageEvent
TouchEvent
XMLHttpRequestProgressEvent
WheelEvent
WebKitTransitionEvent
WebKitAnimationEvent
UIEvent
TextEvent
ProgressEvent
PageTransitionEvent
PopStateEvent
OverflowEvent
MutationEvent
MouseEvent
MessageEvent
KeyboardEvent
HashChangeEvent
ErrorEvent
CustomEvent
CompositionEvent
BeforeLoadEvent
Event
DataView
Float64Array
Float32Array
Uint32Array
Int32Array
Uint16Array
Int16Array
Uint8ClampedArray
Uint8Array
Int8Array
ArrayBuffer
DOMStringMap
WebGLUniformLocation
WebGLTexture
WebGLShaderPrecisionFormat
WebGLShader
WebGLRenderingContext
WebGLRenderbuffer
WebGLProgram
WebGLFramebuffer
WebGLBuffer
WebGLActiveInfo
TextMetrics
ImageData
CanvasRenderingContext2D
CanvasGradient
CanvasPattern
Option
Image
HTMLUnknownElement
HTMLAllCollection
HTMLCollection
HTMLUListElement
HTMLTitleElement
HTMLTextAreaElement
HTMLTableSectionElement
HTMLTableRowElement
HTMLTableElement
HTMLTableColElement
HTMLTableCellElement
HTMLTableCaptionElement
HTMLStyleElement
HTMLSpanElement
HTMLSelectElement
HTMLScriptElement
HTMLQuoteElement
HTMLProgressElement
HTMLPreElement
HTMLParamElement
HTMLParagraphElement
HTMLOutputElement
HTMLOptionElement
HTMLOptGroupElement
HTMLObjectElement
HTMLOListElement
HTMLModElement
HTMLMeterElement
HTMLMetaElement
HTMLMenuElement
HTMLMarqueeElement
HTMLMapElement
HTMLLinkElement
HTMLLegendElement
HTMLLabelElement
HTMLLIElement
HTMLKeygenElement
HTMLInputElement
HTMLImageElement
HTMLIFrameElement
HTMLHtmlElement
HTMLHeadingElement
HTMLHeadElement
HTMLHRElement
HTMLFrameSetElement
HTMLFrameElement
HTMLFormElement
HTMLFontElement
HTMLFieldSetElement
HTMLEmbedElement
HTMLDivElement
HTMLDirectoryElement
HTMLDataListElement
HTMLDListElement
HTMLCanvasElement
HTMLButtonElement
HTMLBodyElement
HTMLBaseFontElement
HTMLBaseElement
HTMLBRElement
HTMLAreaElement
HTMLAppletElement
HTMLAnchorElement
HTMLElement
HTMLDocument
Window
Selection
ProcessingInstruction
EntityReference
Entity
Notation
DocumentType
CDATASection
Comment
Text
Element
Attr
CharacterData
NamedNodeMap
NodeList
Node
Document
DocumentFragment
DOMTokenList
DOMSettableTokenList
DOMImplementation
DOMStringList
DOMException
StyleSheetList
RGBColor
Rect
CSSRuleList
Counter
MediaList
CSSStyleDeclaration
CSSStyleRule
CSSPageRule
CSSMediaRule
CSSImportRule
CSSFontFaceRule
CSSCharsetRule
CSSRule
WebKitCSSFilterValue
WebKitCSSTransformValue
CSSValueList
CSSPrimitiveValue
CSSValue
CSSStyleSheet
StyleSheet
performance
console
devicePixelRatio
styleMedia
parent
opener
frames
self
defaultstatus
defaultStatus
status
name
length
closed
pageYOffset
pageXOffset
scrollY
scrollX
screenTop
screenLeft
screenY
screenX
innerWidth
innerHeight
outerWidth
outerHeight
offscreenBuffering
frameElement
event
crypto
clientInformation
navigator
toolbar
statusbar
scrollbars
personalbar
menubar
locationbar
history
screen

尝试Window.prototype改用:

var windowProp = Object.getOwnPropertyNames(Window.prototype);

for(var i=0; i< windowProp.length; i++){
console.log(windowProp[i]);}

Object.getOwnPropertyDescriptor(Window.prototype,"setTimeout")
//object

这是它返回的内容:

toString
webkitPostMessage
postMessage
close
blur
focus
ondeviceorientation
onwebkittransitionend
onwebkitanimationstart
onwebkitanimationiteration
onwebkitanimationend
onsearch
onreset
onwaiting
onvolumechange
onunload
ontimeupdate
onsuspend
onsubmit
onstorage
onstalled
onselect
onseeking
onseeked
onscroll
onresize
onratechange
onprogress
onpopstate
onplaying
onplay
onpause
onpageshow
onpagehide
ononline
onoffline
onmousewheel
onmouseup
onmouseover
onmouseout
onmousemove
onmousedown
onmessage
onloadstart
onloadedmetadata
onloadeddata
onload
onkeyup
onkeypress
onkeydown
oninvalid
oninput
onhashchange
onfocus
onerror
onended
onemptied
ondurationchange
ondrop
ondragstart
ondragover
ondragleave
ondragenter
ondragend
ondrag
ondblclick
oncontextmenu
onclick
onchange
oncanplaythrough
oncanplay
onblur
onbeforeunload
onabort
getSelection
print
stop
open
showModalDialog
alert
confirm
prompt
find
scrollBy
scrollTo
scroll
moveBy
moveTo
resizeBy
resizeTo
matchMedia
setTimeout
clearTimeout
setInterval
clearInterval
webkitRequestAnimationFrame
webkitCancelAnimationFrame
webkitCancelRequestAnimationFrame
atob
btoa
addEventListener
removeEventListener
captureEvents
releaseEvents
getComputedStyle
getMatchedCSSRules
webkitConvertPointFromPageToNode
webkitConvertPointFromNodeToPage
dispatchEvent
webkitRequestFileSystem
webkitResolveLocalFileSystemURL
openDatabase
TEMPORARY
PERSISTENT
constructor
Object
于 2012-12-24T14:54:20.310 回答