| [ Web Proxy ] |
| Viewing: https://developer.mozilla.org/ru/docs/Web/JavaScript/Reference/Global_Objects/Object/create | [Back] [Original] |
Get to know MDN better
This page was translated from English by the community. Learn more and join the MDN Web Docs community.
This feature is well established and works across many devices and browser versions. Its been available across browsers since 2015 ..
Object.create() .
Object.create(proto[, propertiesObject])
proto, .
propertiesObject . undefined, , ( , , ) , . . Object.defineProperties().
Object.create() Object.create() . , JavaScript.
// Shape
function Shape() {
this.x = 0;
this.y = 0;
}
//
Shape.prototype.move = function (x, y) {
this.x += x;
this.y += y;
console.info(" .");
};
// Rectangle
function Rectangle() {
Shape.call(this); //
}
//
Rectangle.prototype = Object.create(Shape.prototype);
Rectangle.prototype.constructor = Rectangle;
var rect = new Rectangle();
console.log(
" rect Rectangle? " + (rect instanceof Rectangle),
); // true
console.log(" rect Shape? " + (rect instanceof Shape)); // true
rect.move(1, 1); // ' .'
, .
function MyClass() {
SuperClass.call(this);
OtherSuperClass.call(this);
}
MyClass.prototype = Object.create(SuperClass.prototype); //
mixin(MyClass.prototype, OtherSuperClass.prototype); //
MyClass.prototype.myMethod = function () {
// -
};
, . jQuery.extend().
propertiesObject Object.create()var o;
//
o = Object.create(null);
o = {};
// :
o = Object.create(Object.prototype);
// .
// ( , * *.)
o = Object.create(Object.prototype, {
// foo '-'
foo: { writable: true, configurable: true, value: "" },
// bar ( )
bar: {
configurable: false,
get: function () {
return 10;
},
set: function (value) {
console.log(" `o.bar` ", value);
},
/* ES5 :
get function() { return 10; },
set function(value) { console.log(' `o.bar` ', value); } */
},
});
function Constructor() {}
o = new Constructor();
// :
o = Object.create(Constructor.prototype);
// , Constructor ,
// Object.create()
// ,
// 'p' 42
o = Object.create({}, { p: { value: 42 } });
// , :
o.p = 24;
o.p;
// 42
o.q = 12;
for (var prop in o) {
console.log(prop);
}
// 'q'
delete o.p;
// false
// ES3
o2 = Object.create(
{},
{
p: {
value: 42,
writable: true,
enumerable: true,
configurable: true,
},
},
);
Object.prototype.hasOwnProperty.
if (typeof Object.create != "function") {
// ECMA-262, 5, 15.2.3.5
// : http://es5.github.io/#x15.2.3.5
Object.create = (function () {
// ,
function Temp() {}
// Object.prototype.hasOwnProperty
var hasOwn = Object.prototype.hasOwnProperty;
return function (O) {
// 1. Type(O) Object or Null TypeError.
if (typeof O != "object") {
throw TypeError("Object prototype may only be an Object or null");
}
// 2. obj ,
// new Object(), Object
//
// 3. [[Prototype]] obj O.
Temp.prototype = O;
var obj = new Temp();
Temp.prototype = null; // ...
// 4. Properties ,
// obj,
// Object.defineProperties obj
// Properties.
if (arguments.length > 1) {
// Object.defineProperties ToObject .
var Properties = Object(arguments[1]);
for (var prop in Properties) {
if (hasOwn.call(Properties, prop)) {
obj[prop] = Properties[prop];
}
}
}
// 5. obj
return obj;
};
})();
}
| Specification |
|---|
| ECMAScript 2027 LanguageSpecification # sec-object.create |
This page was last modified on 29 . 2026 . by MDN contributors.
ObjectObject.assign()Object.create()Object.defineProperties()Object.defineProperty()Object.entries()Object.freeze()Object.fromEntries()Object.getOwnPropertyDescriptor()Object.getOwnPropertyDescriptors()Object.getOwnPropertyNames()Object.getOwnPropertySymbols()Object.getPrototypeOf()groupBy()hasOwn()Object.is()Object.isExtensible()Object.isFrozen()Object.isSealed()Object.keys()Object.preventExtensions()Object.seal()Object.setPrototypeOf()Object.values()Object.prototype.__defineGetter__()Object.prototype.__defineSetter__()Object.prototype.__lookupGetter__()Object.prototype.__lookupSetter__()Object.prototype.hasOwnProperty()Object.prototype.isPrototypeOf()Object.prototype.propertyIsEnumerable()Object.prototype.toLocaleString()Object.prototype.toString()Object.prototype.valueOf()Object/FunctionObject.prototype.__defineGetter__()Object.prototype.__defineSetter__()Object.prototype.__lookupGetter__()Object.prototype.__lookupSetter__()Object.prototype.hasOwnProperty()Object.prototype.isPrototypeOf()Object.prototype.propertyIsEnumerable()Object.prototype.toLocaleString()Object.prototype.toString()Object.prototype.valueOf()Your blueprint for a better internet.
Portions of this content are 19982026 by individual mozilla.org contributors. Content available under a Creative Commons license.
| Web Proxy Viewer | New URL | Original Page |