[TIMOB-3373] Android: hasOwnProperty function fails
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | Trivial |
Status | Closed |
Resolution | Duplicate |
Resolution Date | 2011-08-10T09:45:20.000+0000 |
Affected Version/s | Release 1.7.2 |
Fix Version/s | n/a |
Components | Android |
Labels | android |
Reporter | Ralf Pfeiffer |
Assignee | Marshall Culpepper |
Created | 2011-04-15T03:43:25.000+0000 |
Updated | 2017-03-22T22:20:32.000+0000 |
Description
The JSLint parser barfs warnings in Developer if you do a 'for' iteration through an object's properties. It states that you need to wrap the for loop's logic with an 'if' condition to filter out properties from the prototype. JSLint is not happy until you do so.
Using the Object.hasOwnProperty(p) function is necessary to do so. So, I dutifully implemented it, and the warnings went away. Then I ran my app on Android. Puke! Android doesn't like that function.
I hereby nominate DT to fix this, because Don seems to rock the known universe.
Please edit the ticket and provide more information.
1) Small source sample that demonstrates the problem.
2) What version(s) of the TiSDK are you using?
3) Have you tried the 1.7 CI build.
I just tested the latest 1.7 build, no luck, same error. You can see it using this plugin https://github.com/appcelerator/TiStorage">https://github.com/appcelerator/TiStorage
JSON.parse('{z: 1}').hasOwnProperty('z');
Gives:
TypeError: Cannot call property hasOwnProperty in object: { 'z': 1 }. It is not a function. It is "object".
I don't get an error from:
({z: 1}).hasOwnProperty('z');
So I assume this has something to do with JSON parsing.
BTW, so far I've been able to work around this with:
Titanium Mobile SDK 1.7.2 on android The following code: var foo = JSON.parse('{"x":1}'); foo.hasOwnProperty('x'); Expected behaviour: foo.hasOwnProperty('x') should return true or false Actual behaviour: a crash saying TypeError: Cannot call property hasOwnProperty in object {'x':1}. It is not a function, it is "object" Detailed enough? (Since when is basic working status of the javascript language a trivial issue btw?)
Closing ticket as duplicate and links to the related ticket have been provided above.