Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 658
alter Avatar asked Aug 20 '10 08:08

alter


People also ask

What is an expando property?

Expando properties are properties added to DOM nodes with JavaScript, where those properties are not part of the object's DOM specification: window. document. foo = 5; // foo is an expando.

What is an Expando?

EXPANDO is an expansive mortar chemical that cracks rocks and concrete, without using explosives. It is a concrete cutting, granite breaking and general demolition solution.


2 Answers

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.

like image 118
Greg Perham Avatar answered Sep 24 '22 18:09

Greg Perham


Simply put expando property is a property which does not exist originally. In Internet Explorer if you create such a property for a DOM element you may end up with a memory leak. Here is an example:

var div = document.getElementsByTagName('div')[0];
div.someProperty = true; // 'someProperty' is an expando property which may introduce a memory leak in IE

More info can be found in the Understanding and Solving Internet Explorer Leak Patterns

like image 28
Atanas Korchev Avatar answered Sep 22 '22 18:09

Atanas Korchev