Export (0) Print
Expand All

prototype Property (Error)

Returns a reference to the prototype for an error.

error.prototype

The error argument is the name of an error.

Use the prototype property to provide a base set of functionality to an Error. New instances of an object "inherit" the behavior of the prototype assigned to that object.

For example, to add a method to the Error object that returns the value of the largest element of the array, declare the function, add it to Error.prototype, and then use it.

function getSeverity(){
    if (this.number > 1000)
        return "high";
    else
        return "low";
}
Error.prototype.getSev = getSeverity;
var myError = new Error();
myError.number = 5000;

document.write(myError.getSev()); 

// Output: high

All intrinsic JavaScript objects have a prototype property that is read-only. Properties and methods may be added to the prototype, but the object may not be assigned a different prototype. However, user-defined objects may be assigned a new prototype.

Supported in the following document modes: Quirks, Internet Explorer 6 standards, Internet Explorer 7 standards, Internet Explorer 8 standards, Internet Explorer 9 standards, Internet Explorer 10 standards, Internet Explorer 11 standards. Also supported Store apps (Windows 8 and Windows Phone 8.1). See Version Information.

Show:
© 2015 Microsoft