JavaScript uses hasownproperty to determine whether a property is an inherent property of an object

From , 5 Years ago, written in JavaScript, viewed 91 times.
URL https://pastebin.vip/view/72fe6f9f
  1. function Book(title, author) {  
  2.    this.title = title;  
  3.    this.author = author;  
  4.   }  
  5.    Book.prototype.price = 9.99;  
  6.    Object.prototype.copyright = "herongyang.com";  
  7.    var myBook = new Book("JavaScript Tutorials", "Herong Yang");  
  8.  
  9.    // Dumping built-in properties at the base prototype level  
  10.    document.writeln("/nObject.prototype's built-in properties:");  
  11.    dumpProperty(Object.prototype, "constructor");  
  12.    dumpProperty(Object.prototype, "hasOwnProperty");  
  13.    dumpProperty(Object.prototype, "isPrototypeOf");  
  14.    dumpProperty(Object.prototype, "toString");  
  15.    dumpProperty(Object.prototype, "valueOf");  
  16.    dumpProperty(Object.prototype, "copyright");  
  17.  
  18.    // Dumping built-in properties at the my prototype level  
  19.    document.writeln("/n==================/nBook.prototype's built-in properties:");  
  20.    dumpProperty(Book.prototype, "constructor");  
  21.    dumpProperty(Book.prototype, "hasOwnProperty");  
  22.    dumpProperty(Book.prototype, "isPrototypeOf");  
  23.    dumpProperty(Book.prototype, "toString");  
  24.    dumpProperty(Book.prototype, "valueOf");  
  25.    dumpProperty(Book.prototype, "copyright");  
  26.  
  27.    // Dumping built-in properties at the object level  
  28.    document.writeln("/n==================/nmyBook's built-in properties:");  
  29.    dumpProperty(myBook, "constructor");  
  30.    dumpProperty(myBook, "hasOwnProperty");  
  31.    dumpProperty(myBook, "isPrototypeOf");  
  32.    dumpProperty(myBook, "toString");  
  33.    dumpProperty(myBook, "valueOf");  
  34.    dumpProperty(myBook, "copyright");  
  35.      
  36. function dumpProperty(object, property) {  
  37.    var inheritance;  
  38.    if (object.hasOwnProperty(property))  
  39.       inheritance = "Local";  
  40.    else  
  41.       inheritance = "Inherited";  
  42.    document.writeln(property+": "+inheritance+": "  
  43.       +object[property]);  
  44. }
  45. //javascript/7073

Reply to "JavaScript uses hasownproperty to determine whether a property is an inherent property of an object"

Here you can reply to the paste above

captcha

https://burned.cc - Burn After Reading Website