Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
624 views
in Technique[技术] by (71.8m points)

memory leaks - JavaScript: What is the Expando Property?

I came across this property while reading about JavaScript memory leaks. I was informed that this property is supported only in Internet Explorer and is responsible for circular reference.

I tried to check and found this property not available in any of the browsers. Can anyone offer any insight on this property and how is it linked to memory leaks?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I came here with the same question, also after reading an article about memory leaks. I was still confused after reading the answers here, so I thought I'd share my findings after some more research.

It can be confusing in JavaScript to know if something like .expandoProperty is part of the language or somebody being clever with property names.

obj.expandoProperty in the memory leak article could just as well have been obj.foo. The point they are trying to get across by using ".expandoProperty" is that the property did not exist as part of the object originally.

var obj = {myProp: ''};
obj.myProp    = 'foo';  //myProp is not an expando property
obj.myNewProp = 'bar';  //myNewProp is an expando property

Add to the mix: .expando is an IE-only property that "sets or retrieves a value indicating whether arbitrary variables can be created within the object." MSDN article

See also generalized discussion of expando properties on StackOverflow here.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...