| [ Web Proxy ] |
| Viewing: https://developer.mozilla.org/zh-TW/docs/Web/JavaScript/Reference/Operators/new | [Back] [Original] |
Get to know MDN better
This feature is well established and works across many devices and browser versions. Its been available across browsers since 20157.
car car makemodelyear
function car(make, model, year) {
this.make = make;
this.model = model;
this.year = year;
}
this
mycar
mycar = new car("Eagle", "Talon TSi", 1993);
mycar mycar.make "Eagle"mycar.year 1993
new car
kenscar = new car("Nissan", "300ZX", 1992);
vpgscar = new car("Mazda", "Miata", 1990);
person
function person(name, age, sex) {
this.name = name;
this.age = age;
this.sex = sex;
}
person
rand = new person("Rand McKinnon", 33, "M");
ken = new person("Ken Jones", 39, "M");
car person owner
function car(make, model, year, owner) {
this.make = make;
this.model = model;
this.year = year;
this.owner = owner;
}
car1 = new car("Eagle", "Talon TSi", 1993, rand);
car2 = new car("Nissan", "300ZX", 1992, ken);
rand ken owners car2 owner
car2.owner.name
car1.color = "black";
color car1 "black" car
This page was last modified on 2025716 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 |