Overriding hasOwnProperty on window

20 views
Skip to first unread message

Sesha Sendhil Subramanian

unread,
Jan 18, 2015, 6:08:16 AM1/18/15
to js...@googlegroups.com
I was trying to parse a site which implemented its own version of hasOwnProperty. However, the native implementation is what was getting picked up.

To validate this out I tried parsing a simple html as follows

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>test</title>
  <script src="//code.jquery.com/jquery-1.10.2.js"></script>
</head>
<body>
<p>I would like to say: </p>

<script>
function hasOwnProperty(){
  try {
    $('body').append('<div>success</div>');
  }catch(e){
    $('body').append('<div>'+e+'</div>');
  }
}

try {
  hasOwnProperty();
  $('body').append('<div>Success2</div>');
}catch(e){
  $('body').append('<div class="two">'+e+'</div>');
}
</script>
</body>
</html>

I get an error "TypeError: Cannot convert null to object" which tells me the native implementation is being called

When I change the name of the function though, my function is executed.

Is this a known issue? How do I handle this?
Reply all
Reply to author
Forward
0 new messages