[ Web Proxy ]
URL:
Viewing: https://developer.mozilla.org/ru/docs/Web/JavaScript/Reference/Global_Objects/Object/constructor [Back]  [Original]

Object.prototype.constructor - JavaScript | MDN

This page was translated from English by the community. Learn more and join the MDN Web Docs community.

View in English Always switch to English

Object.prototype.constructor

Baseline Widely available

This feature is well established and works across many devices and browser versions. Its been available across browsers since 2015 ..

Object, . , , , . , 1, true "test", .

In this article

constructor :

js
var o = {};
o.constructor === Object; // true

var a = [];
a.constructor === Array; // true

var n = new Number(3);
n.constructor === Number; // true

:

Tree theTree. constructor theTree.

js
function Tree(name) {
  this.name = name;
}

var theTree = new Tree(" ");
console.log("theTree.constructor  " + theTree.constructor);

:

js
theTree.constructor  function Tree(name) {
  this.name = name;
}

:

, . true, 1 "", . , constructor .

js
function Type() {}

var types = [
  new Array(),
  [],
  new Boolean(),
  true, //  
  new Date(),
  new Error(),
  new Function(),
  function () {},
  Math,
  new Number(),
  1, //  
  new Object(),
  {},
  new RegExp(),
  /(?:)/,
  new String(),
  "", //  
];

for (var i = 0; i < types.length; i++) {
  types[i].constructor = Type;
  types[i] = [
    types[i].constructor,
    types[i] instanceof Type,
    types[i].toString(),
  ];
}

console.log(types.join("\n"));

:

js
function Type() {},false,
function Type() {},false,
function Type() {},false,false
function Boolean() {
    [native code]
},false,true
function Type() {},false,Mon Sep 01 2014 16:03:49 GMT+0600
function Type() {},false,Error
function Type() {},false,function anonymous() {

}
function Type() {},false,function () {}
function Type() {},false,[object Math]
function Type() {},false,0
function Number() {
    [native code]
},false,1
function Type() {},false,[object Object]
function Type() {},false,[object Object]
function Type() {},false,/(?:)/
function Type() {},false,/(?:)/
function Type() {},false,
function String() {
    [native code]
},false,

Specification
ECMAScript 2027 LanguageSpecification
# sec-object.prototype.constructor


Web Proxy Viewer  |  New URL  |  Original Page