Built-in Properties and Methods in "Object.prototype"

This section provides a quick description of built-in default properties and methods in 'Object.prototype'. A tutorial example is provided to dump what's in 'Object.prototype'.

As I mentioned in the previous section, the default prototype object is created from the "Object()" constructor function. Its prototype object, "Object.prototype", is the base prototype object of all other prototype objects. Therefor, properties of "Object.prototype" will be inherited by all objects.

Because of this nature, JavaScript provides a number built-in properties and methods in "Object.prototype" accessible by all objects through the inheritance tree. Some of them are listed below:

Let's first confirm that those properties and method do exist in "Object.prototype". To do this I wrote the following tutorial example to print out their values. Notice that how I use the hasOwnProperty() method to separate

<html>
<!-- Inheritance_Built_in_Propertie_and_Method.html
   Copyright (c) 2013 by Dr. Herong Yang, herongyang.com
-->
<head>
<title>Built-in Properties and Methods in Object.prototype</title>
</head>
<body>
<pre>
<script type="text/javascript">

   // Adding a property to the base prototype
   Object.prototype.copyright = "herongyang.com";

   // Dumping some built-in properties
   document.writeln("\nObject.prototype's built-in properties:");
   dumpProperty(Object.prototype, "constructor");
   dumpProperty(Object.prototype, "hasOwnProperty");
   dumpProperty(Object.prototype, "isPrototypeOf");
   dumpProperty(Object.prototype, "toString");
   dumpProperty(Object.prototype, "valueOf");
   
   // Dumping the user added property
   document.writeln("\nObject.prototype's user added properties:");
   dumpProperty(Object.prototype, "copyright");

function dumpProperty(object, property) {
   var inheritance; 
   if (object.hasOwnProperty(property)) 
      inheritance = "Local";
   else 
      inheritance = "Inherited";
   document.writeln("   "+property+": "+inheritance+": "
      +object[property]);
}
</script>
</pre>
</body>
</html>

The output of this tutorial example tells us that those properties and methods do exists and local to the "Object.prototype" object. However, JavaScript does not want to show us their values, the definitions of functions in all cases.

Object.prototype's built-in properties:
   constructor: Local: function Object() {
    [native code]
}
   hasOwnProperty: Local: function hasOwnProperty() {
    [native code]
}
   isPrototypeOf: Local: function isPrototypeOf() {
    [native code]
}
   toString: Local: function toString() {
    [native code]
}
   valueOf: Local: function valueOf() {
    [native code]
}

Object.prototype's user added properties:
   copyright: Local: herongyang.com

Now I am ready to update my diagram on JavaScript object inheritance model:
Built-in Properties and Methods

Table of Contents

 About This Book

 Introduction to JavaScript

 ECMAScript Language Specification and JavaScript Dialects

 Data Types, Variables and Expressions

 Flow Control Statements

 Creating, Accessing, and Manipulating Arrays

 Defining and Calling Functions

 Web Browser Supporting JavaScript

 Server-Side and Client-Side Web Scripting

 Introduction to Objects

 Defining Your Own Object Types

Inheritance of Properties and Methods through the Prototype Object Chain

 Inheriting from Constructor's Prototype Object

 Changing the Constructor's Prototype Object

 Inheriting Properties from Two Level Prototype Objects

Built-in Properties and Methods in "Object.prototype"

 Using "hasOwnProperty()" Method to Test Inherited Properties

 Setting the "constructor" Property in the "prototype" Object

 Adding Local Methods at the Object Level

 Adding Inherited Methods at the Prototype Level

 Building Multiple Levels of Prototype Objects

 Prototype Object Chain Summary

 'jrunscript' - JavaScript Shell Command from JDK

 Using Functions as "Function" Objects

 Introduction to Built-in Object Types

 W3C's Document Object Model (DOM) Specifications

 References

 PDF Printing Version