0

I am getting the error "Can't convert undefined to object on the line return hasOwnProperty(prop); and I simply cannot figure out where the problem lies. I can post more of the code if necessary.

getCardProperty : function (card, prop, def) {
    if (typeof def === "undefined") {
        def = null;
    }

    // json synckolab object
    if (card.synckolab) {
        if (card.hasOwnProperty(prop)) // TODO better check for undefined?
        {
            return hasOwnProperty(prop);
        }
        return null;
    }
user1514992
  • 33
  • 3
  • 7
  • I had the same problem, and did know why happens, but when I set up correct html code (with table tags and divs correctly closed) I do not get any more this error!! – albanx Mar 28 '13 at 09:16

1 Answers1

1

hasOwnProperty(prop) doesn't exist - you need to qualify it with an object name. Just change it to card.hasOwnProperty(prop).

You can simplify it further:

if (card.synckolab) {
    return card.hasOwnProperty(prop) || null;
}

This will return true or null. Or you can simplify even further:

if (card.synckolab) {
    return card.hasOwnProperty(prop);
}

This will return true or false.

chrisfrancis27
  • 4,516
  • 1
  • 24
  • 32