Returns the prototype of an object.
SyntaxObject.getPrototypeOf( object )
The prototype of the object argument. The prototype is also an object.
ExamplesThe following example illustrates the use of the Object.getPrototypeOf function.
function Pasta(grain, width) {
this.grain = grain;
this.width = width;
}
var spaghetti = new Pasta("wheat", 0.2);
var proto = Object.getPrototypeOf(spaghetti);
proto.foodgroup = "carbohydrates";
document.write(spaghetti.foodgroup + " ");
var result = (proto === Pasta.prototype);
document.write(result + " ");
var result = proto.isPrototypeOf(spaghetti);
document.write(result);
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);
Exceptions
If the object argument is not an object, a TypeError exception is thrown.
See also Other articles AttributionsMicrosoft Developer Network: Article
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4