我正在学习 JavaScript,我创建了三个具有一些属性的不同对象:Person、House 和 Car。
let House = function(city, postalCode, street, streetNumber){
this.city = city;
this.postalCode = postalCode;
this.street = street;
this.streetNumber = streetNumber;
return {
getAddress: function() {
return {
'address': {
'city': city,
'postalCode': postalCode,
'street': street,
'streetNumber': streetNumber
}
};
}
};
};
let Person = function(name, surname, yearOfBirth, monthOfBirth, dayOfBirth, bornCity, employment){
this.name = name;
this.surname = surname;
this.yearOfBirth = yearOfBirth;
this.monthOfBirth = monthOfBirth;
this.dayOfBirth = dayOfBirth;
this.bornCity = bornCity;
this.employment = employment;
return {
getFullPerson: function() {
return {
'personalInformation': {
'name': name,
'surname': surname,
'dateOfBirth': {
'year': yearOfBirth,
'month': monthOfBirth,
'day': dayOfBirth
},
'bornCity': bornCity
},
'employment': employment,
'home': getAddress(), // pseudocode
'car': getCar() // pseudocode
};
}
};
};
我想在这些对象之间创建链接,因为我需要调用,例如,谁住在房子里,反之亦然;但我不清楚如何做到这一点。
繁花不似锦
慕容3067478
相关分类