Welcome to WebmasterWorld Guest from 54.144.246.252

Forum Moderators: open

IE6 issue with hasOwnProperty

weirdness follows

   
3:58 pm on Feb 17, 2012 (gmt 0)



Having issues with this code in IE6. Works perfectly in Chrome. Why is the error thrown on dimFeetSelect.hasOwnProperty('value')?


for (bendDimension in bendDimensions) {
if (bendDimensions.hasOwnProperty(bendDimension)) {
dimFeet = 0;
dimInches = 0;
bendDimensionObject = bendDimensions[bendDimension];alert('made bendDimensionObject');
dimSelect = 'tr.dimension-' + bendDimension;
dimFeetSelector = $(dimSelect + ' input.rebar-dimension-feet');alert('successful dimFeetSelect: ' + dimFeetSelector);
dimFeetSelect = dimFeetSelector[0];alert('passed dimFeetSelect specifier: ' + dimFeetSelect);
alert('testing values');
alert('typeof1: ' + typeof dimFeetSelect); // [object]
alert('typeof2: ' + typeof dimFeetSelect.hasOwnProperty); // undefined
alert('typeof3: ' + typeof dimFeetSelect.value); // string
if (Object.prototype.toString.apply(dimFeetSelect) === '[object Array]') {
alert('array');
} else {
alert('object');
} // object
alert('!isNaN?: ' + !isNaN(dimFeetSelect.value)); // true
alert('value: ' + dimFeetSelect.value); // correct value is printed
alert('hasProperty?: ' + dimFeetSelect.hasOwnProperty('value')); // error thrown
}
}
4:46 pm on Feb 17, 2012 (gmt 0)

WebmasterWorld Senior Member penders is a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month



What error are you getting?
6:06 pm on Feb 17, 2012 (gmt 0)



I'm in IE6. Not sure how to get the error's information.

Anyways, I took out .hasOwnProperty and it works fine. I figured I just don't need that statement. Weird quirk though.
6:29 pm on Feb 17, 2012 (gmt 0)

WebmasterWorld Senior Member penders is a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month



Not sure how to get the error's information.


How did you know there was an error?
6:39 pm on Feb 17, 2012 (gmt 0)



When the code comes to the alert with the .hasOwnProperty, my code catches the error and throws a new error with a custom message to tell the form user there is invalid input.
6:52 pm on Feb 17, 2012 (gmt 0)

WebmasterWorld Senior Member penders is a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month



Ah OK, you would need to examine the 'message' and 'name' properties of the original error object in your catch block before throwing a new exception.
6:54 pm on Feb 17, 2012 (gmt 0)

WebmasterWorld Senior Member fotiman is a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month



I could be wrong about this, but:

dimFeetSelector = $(dimSelect + ' input.rebar-dimension-feet');
dimFeetSelect = dimFeetSelector[0];

Is this jQuery? If so, I'm not sure what dimFeetSelector[0] would return. Is it an HTMLElement object? Or another jQuery object? The jQuery object defines its own prototype that does not include a hasOwnProperty method. However, it does have a "hasOwn" method (which is a reference to Object.prototype.hasOwnProperty). So if dimFeetSelect is a jQuery object, then you can probably call hasOwn instead of hasOwnProperty (though it doesn't explain why it would work in Chrome).
9:03 pm on Feb 17, 2012 (gmt 0)



dimFeetSelector[0] is an HTMLElement object, and yes, I am using jQuery.
 

Featured Threads

Hot Threads This Week

Hot Threads This Month