danriegsecker / swfobject

Automatically exported from code.google.com/p/swfobject
0 stars 0 forks source link

Filtering properties in Object.prototype then storing back to an object defeats the purpose #197

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
In several places with this comment "// Filter out prototype additions from 
other potential libraries" 
there is code similar to the following:

                var att = {};
                if (attObj && typeof attObj === OBJECT) {
                    for (var i in attObj) {
                        if (attObj[i] != Object.prototype[i]) { // Filter out prototype additions 
from other potential libraries
                            att[i] = attObj[i];
                        }
                    }
                }

"att" will have the exact same properties you just filtered because "att" 
itself is an instance of Object 
and will get those properties from Object.prototype.

Solution: store filtered results as key/value pairs in an array, or do the test 
as you're actually using 
the object.

Additionally, the Object.hasOwnProperty() method is a better way of performing 
the test.

Original issue reported on code.google.com by yacht...@gmail.com on 19 Oct 2008 at 2:17

GoogleCodeExporter commented 9 years ago
Yes, you're right that doesn't make sense at all :-)

We will change this in the next release.

Original comment by bobbyvandersluis on 19 Oct 2008 at 9:35

GoogleCodeExporter commented 9 years ago
A few notes:
- we have to copy the attObj, because web authors often use attObj for multiple 
SWF
definitions, so we need to avoid using references
- a test like: if (attObj[i] != Object.prototype[i])... doesn't make sense in 
the
situation above, and should only be used when actually using the object (what 
this
issue report is about)
- Object.hasOwnProperty() (as proposed in this issue report) should not be used 
in
this case, because we are copying over the attObj into our new att Object, and
because of this all copied over properties become "own properties", so in our 
case it
is better to use the Object.prototype test to see whether properties are defined
externally ouside the language

Original comment by bobbyvandersluis on 21 Nov 2008 at 9:25

GoogleCodeExporter commented 9 years ago
As an addition:
- Object.hasOwnProperty() is not supported by Safari 1.3 and lower, while 
SWFObject
2.2 does not support Safari 1.2 and lower anymore (it shows alternative content
instead), while it does support Safari 1.3

Original comment by bobbyvandersluis on 21 Nov 2008 at 12:48

GoogleCodeExporter commented 9 years ago
Fix has been made in SWFobject 2.2 alpha2.

Original comment by bobbyvandersluis on 21 Nov 2008 at 1:07

GoogleCodeExporter commented 9 years ago
Included in the SWFObject 2.2 beta1 release

Original comment by bobbyvandersluis on 16 Apr 2009 at 3:05