Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-3373] Android: hasOwnProperty function fails

GitHub Issuen/a
TypeBug
PriorityTrivial
StatusClosed
ResolutionDuplicate
Resolution Date2011-08-10T09:45:20.000+0000
Affected Version/sRelease 1.7.2
Fix Version/sn/a
ComponentsAndroid
Labelsandroid
ReporterRalf Pfeiffer
AssigneeMarshall Culpepper
Created2011-04-15T03:43:25.000+0000
Updated2017-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.

Comments

  1. Don Thorp 2011-04-15

    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.

  2. Nate 2011-04-15

    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

  3. j1m 2011-04-15

    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.

  4. j1m 2011-04-15

    BTW, so far I've been able to work around this with:

       var json_parse = function (s) {
           var result = {};
           s = JSON.parse(s);
           for (var name in s) {
               if (! (name in result)) {
                   result[name] = s[name];
               }
           }
           return result;
       };
       
  5. Karl Åström 2011-08-05

    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?)
  6. Lee Morris 2017-03-22

    Closing ticket as duplicate and links to the related ticket have been provided above.

JSON Source