get rid of useless for..in loop in getStyle #2410

Merged
merged 1 commit into from Aug 20, 2012
@@ -114,10 +114,9 @@ Element.implement({
property = (property == 'float' ? floatName : property).camelCase();
var result = this.style[property];
if (!result || property == 'zIndex'){
- result = [];
- for (var style in Element.ShortStyles){
- if (property != style) continue;
- for (var s in Element.ShortStyles[style]) result.push(this.getStyle(s));
+ if (Element.ShortStyles.hasOwnProperty(property)){
@ibolmo
ibolmo Aug 20, 2012 MooTools member

Particular reason why not just:

if (Element.ShortStyles[property]){

?

@gonchuki
gonchuki Aug 20, 2012 collaborator

defensive coding, if the Object prototype ever gains a property named exactly like a CSS style that piece of code won't blow up into pieces. That includes both future standards and nasty users/3rd party scripts adding stuff to the Object prototype.

@ibolmo
ibolmo Aug 20, 2012 MooTools member

That's a good idea then.

+ result = [];
+ for (var s in Element.ShortStyles[property]) result.push(this.getStyle(s));
return result.join(' ');
}
result = this.getComputedStyle(property);