2012-12-24 56 views
3

Object.getOwnPropertyNames(window)不返回返回數組中的setTimeout值。Object.getOwnPropertyNames(window)不返回數組中的setTimeout

這裏有什麼問題?

之後,我想檢查setTimeout屬性的屬性描述符對象,但Object.getOwnPropertyDescriptor(window,"setTimeout")返回undefined。

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

我最近有關於事件處理程序的類似問題;事實證明這些屬性是在'Window.prototype'(因此它們不是* own *屬性)。 – bfavaretto

+0

@bfavaretto發表您的評論作爲答案。 – Engineer

+0

@bfavaretto,感謝您的澄清,請將其發佈爲答案,我與窗口和窗口混淆。我試過window.prototype,但它是未定義的。 Window.prototype是有意義的,因爲構造函數通常以CAPS開始。 –

回答

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 
+0

@打開你的歡迎? – Neal