| [ Web Proxy ] |
| Viewing: https://developer.mozilla.org/ru/docs/Web/JavaScript/Reference/Operators/new | [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 ..
( ) new , , .
new constructor[([arguments])]
constructor, .
arguments, .
, , :
new., , . . .
new Foo(...) , :
Foo.prototype.Foo this, . new Foo new Foo(), , Foo . . , car1.color = "black" color car1, "black". . , Car.
Function.prototype. , , - . color null car, "black" car1. prototype.
function Car() {}
car1 = new Car();
console.log(car1.color); // undefined
Car.prototype.color = null;
console.log(car1.color); // null
car1.color = "black";
console.log(car1.color); // black
, . car, : , .
function Car(make, model, year) {
this.make = make;
this.model = model;
this.year = year;
}
car:
var mycar = new Car("Eagle", "Talon TSi", 1993);
mycar . , mycar.make "Eagle", mycar.year 1993, .
car new. :
var kenscar = new Car("Nissan", "300ZX", 1992);
, person:
function Person(name, age, sex) {
this.name = name;
this.age = age;
this.sex = sex;
}
:
var rand = new Person("Rand McNally", 33, "M");
var ken = new Person("Ken Jones", 39, "M");
car, , owner:
function Car(make, model, year, owner) {
this.make = make;
this.model = model;
this.year = year;
this.owner = owner;
}
car:
var car1 = new Car("Eagle", "Talon TSi", 1993, rand);
var car2 = new Car("Nissan", "300ZX", 1992, ken);
. car2, :
car2.owner.name;
| Specification |
|---|
| ECMAScript 2027 LanguageSpecification # sec-new-operator |
This page was last modified on 7 . 2023 . by MDN contributors.
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 |