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

Object.prototype.__proto__ - 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.__proto__

Deprecated

Avoid using this feature in new projects. Changing __proto__ is slow and can cause surprising bugs. This feature may be a candidate for removal from web standards or browsers.

: [[Prototype]] , JavaScript, , JavaScript. , obj.__proto__ = ..., , , [[Prototype]] . , [[Prototype]] . [[Prototype]], Object.create().

: Object.prototype.__proto__, ECMAScript 6. , Object.getPrototypeOf().

In this article

__proto__ Object ( ), [[Prototype]] ( null), .

__proto__ . EcmaScript, . __proto__ ECMAScript 6 . , [[Prototype]] , , .

__proto__ , [[Prototype]] . Object.create(). .

js
var shape = {},
  circle = new Circle();

//   
shape.__proto__ = circle;
//   
console.log(shape.__proto__ === circle); // true

: , proto .

__proto__ [[Prototype]] . , , Object. Function. , new fun, fun -, JavaScript (Array, Boolean, Date, Number, Object, String , JavaScript), fun.prototype. , new fun, fun , , fun.prototype new fun. fun.prototype , fun [[Prototype]], new fun [[Prototype]].

__proto__ [[Prototype]] . Object.isExtensible(): , TypeError. null. .

, , .

__proto__ Object , . __proto__ , , , Object, Object, . Object - __proto__, Object.

js
var noProto = Object.create(null);

console.log(typeof noProto.__proto__); // undefined
console.log(Object.getPrototypeOf(noProto)); // null

noProto.__proto__ = 17;

console.log(noProto.__proto__); // 17
console.log(Object.getPrototypeOf(noProto)); // null

var protoHidden = {};
Object.defineProperty(protoHidden, "__proto__", {
  value: 42,
  writable: true,
  configurable: true,
  enumerable: true,
});

console.log(protoHidden.__proto__); // 42
console.log(Object.getPrototypeOf(protoHidden) === Object.prototype); // true

Employee, , __proto__ , prototype.

js
//  ,   
function Employee() {
  /*   */
}

//    Employee
var fred = new Employee();

//   
fred.__proto__ === Employee.prototype; // true

fred Employee, fred.__proto__ :

js
function Cow() {
  /*   */
}

//  __proto__  
fred.__proto__ = Cow.prototype;

fred Cow.prototype, Employee.prototype, , Employee.prototype.

, , __proto__ :

js
var obj = {};
Object.preventExtensions(obj);

obj.__proto__ = {}; //  TypeError

, __proto__ Object.prototype, null:

js
var b = {};

Object.prototype.__proto__ = Object.create(
  null, // [[Prototype]]
  {
    hi: {
      value: function () {
        alert("hi");
      },
    },
  },
);

b.hi();

__proto__ Object null, , , , null, TypeError __proto__, null ( Object ).

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


Web Proxy Viewer  |  New URL  |  Original Page