17.hasOwnProperty.html 650 B

1234567891011121314151617181920212223
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>Document</title>
  7. </head>
  8. <body>
  9. <script>
  10. function Person() {
  11. }
  12. Person.prototype.name = '我是图图';
  13. let p1 = new Person();
  14. p1.age = 10;
  15. console.log(p1);
  16. // in 在当前实例及原型上查找 找到 返回true;找不到 返回false
  17. // console.log("x" in p1);
  18. // hasOwnProperty 只检查实例自身 找到 返回true;找不到 返回false
  19. console.log(p1.hasOwnProperty("name"));
  20. </script>
  21. </body>
  22. </html>