homepage Welcome to WebmasterWorld Guest from 54.161.240.10
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

    
IE6 issue with hasOwnProperty
weirdness follows
b_radikal




msg:4418833
 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
}
}

 

penders




msg:4418850
 4:46 pm on Feb 17, 2012 (gmt 0)

What error are you getting?

b_radikal




msg:4418890
 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.

penders




msg:4418901
 6:29 pm on Feb 17, 2012 (gmt 0)

Not sure how to get the error's information.


How did you know there was an error?

b_radikal




msg:4418905
 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.

penders




msg:4418909
 6:52 pm on Feb 17, 2012 (gmt 0)

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.

Fotiman




msg:4418910
 6:54 pm on Feb 17, 2012 (gmt 0)

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).

b_radikal




msg:4418959
 9:03 pm on Feb 17, 2012 (gmt 0)

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

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved