References the function which created the instance of the Array object.
SyntaxarrayObj.constructor
Return Value
The function object which constructed the Array instance.
ExamplesThe following example illustrates the use of the constructor property.
var x = new Array();
if (x.constructor == Array)
document.write("Object is an Array.");
else
document.write("Object is not an Array.");
Remarks
The constructor property is a member of the prototype of every object that has a prototype. This includes all intrinsic JavaScript objects except the Global and Math objects. If the JavaScript interpreter falls back to their prototype object, the constructor property references the native Object.prototype.constructor
.
var my_obj = Math;
document.write(my_obj.constructor === Math);
// Output: false
The constructor property is only read-only for primitive values such as 1, true and "test".
var my_obj = new Number(100);
my_obj.constructor = String; // overwritten
document.write(my_obj.constructor);
// Output: function String() { [native code] }
my_obj = 100;
my_obj.constructor = String; // can't be overwritten
document.write(my_obj.constructor);
// Output: function Number() { [native code] }
See also External resources
Specification
ECMAScript® Language Specification Standard ECMA-262 5.1 Edition / June 2011
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