Loading ...
Sorry, an error occurred while loading the content.

Re: In IE some objects lack hasOwnProperty?

Expand Messages
  • Douglas Crockford
    ... for (key in object) { if (Object.prototype.hasOwnProperty.call(object, key)) { ... } } hasOwnProperty should have been an operator, not a method, because
    Message 1 of 2 , Apr 4 9:46 PM
    • 0 Attachment
      --- In jslint_com@yahoogroups.com, Erik Eckhardt <erik@...> wrote:
      >
      > In IE 7 I tried using hasOwnProperty on document.styleSheets[0].rules[0] and
      > found out that the rule object returned from the expression doesn't have
      > that function!
      >
      > I noticed in jQuery a clever way to get around this using call on
      > Object.hasOwnProperty. However, jslint doesn't recognize this as valid
      > filtering.
      >
      > Would you suggest how to handle this problem?

      for (key in object) {
      if (Object.prototype.hasOwnProperty.call(object, key)) {
      ...
      }
      }

      hasOwnProperty should have been an operator, not a method, because being a method, it is prone to these sorts of problems. But it is what it is, so you have to work around that.
    Your message has been successfully submitted and would be delivered to recipients shortly.