【发布时间】:2021-04-26 12:50:26
【问题描述】:
const myCountry = function (country, capital, language, population) {
(this.country = country),
(this.capital = capital),
(this.language = language),
(this.population = population),
(this.neighbours = []);
};
const Utopia = new myCountry("Utopia", "rabat", "arabic", "18 million", [
"algeria",
"tunisia",
]);
【问题讨论】:
-
在构造函数中添加optional
neighboursparameter,例如function MyCountry(country, capital, language, population, neighbours = [])并使用this.neighbours = neighbours -
谢谢!可以,忘记参数了
标签: javascript object constructor