When you are assigning a property of an object to a variable you can skip writing the assignment if the property name and variable name are same.
const nameOfFacility = "Swimming Pool";
const canbeBooked = false;
const isSlotted = false;
const capacity = 25;
// One way of writing
const clubFacility = {
nameOfFacility: nameOfFacility,
canbeBooked: canbeBooked,
isSlotted: isSlotted,
capacity: capacity
}
// Another way of writing the same thing
const clubFacility = {
nameOfFacility,
canbeBooked,
isSlotted,
capacity
}
You can also define the methods in shorthand
// One way of writing
const facility = {
fetchFacilityDetails: function(parameter) {
},
addFacilityDetails: function(parameter) {
},
removeFacilityDetails: function(parameter) {
},
addDetailsToFacility: function(parameter) {
},
removeDetailsFromFacility: function(parameter) {
},
}
// Another way of writing the same thing
const facility = {
fetchFacilityDetails(parameter) {
},
addFacilityDetails(parameter) {
},
removeFacilityDetails(parameter) {
},
addDetailsToFacility(parameter) {
},
removeDetailsFromFacility(parameter) {
},
}
Peace ✌️