Object.getPrototypeOf Function (JavaScript)
JavaScript - Internet Explorer 10
Returns the prototype of an object.
Object.getPrototypeOf(object)
The following example illustrates the use of the Object.getPrototypeOf function.
// Create a constructor function. function Pasta(grain, width) { this.grain = grain; this.width = width; } // Create an object from the pasta constructor. var spaghetti = new Pasta("wheat", 0.2); // Obtain the prototype from the object. var proto = Object.getPrototypeOf(spaghetti); // Add a property to the prototype and validate that // the original object has the property. proto.foodgroup = "carbohydrates"; document.write(spaghetti.foodgroup + " "); // Verify that the prototype obtained from the object // is the same as the prototype of the constructor. var result = (proto === Pasta.prototype); document.write(result + " "); // Verify that prototype obtained from the object // is a prototype of the original object. var result = proto.isPrototypeOf(spaghetti); document.write(result); // Output: carbohydrates true true
The following example uses the Object.getPrototypeOf function to validate data types.
var reg = /a/; var result = (Object.getPrototypeOf(reg) === RegExp.prototype); document.write(result + " "); var err = new Error("an error"); var result = (Object.getPrototypeOf(err) === Error.prototype); document.write(result); // Output: true true
Supported in the following document modes: Internet Explorer 9 standards and Internet Explorer 10 standards. Also supported in Windows Store apps. See Version Information.
Not supported in the following document modes: Quirks, Internet Explorer 6 standards, Internet Explorer 7 standards, Internet Explorer 8 standards.