I have a var in ES5 code which looks like below.
var options = {
clientId : clientId
keepAlive : keepAlive,
clean : clean,
reconnectPeriod : reconnectPeriod,
will : lastWillMessage
};
I could change this to ES6 by saying
let options = {clientId,keepAlive,reconnectPeriod,lastWillMessage};
But how do I do this if I don't want to pass values for all the properties? For instance I just want to pass the clientId and the keepAlive. Rest will have the default values set by MQTT module. So how can I set values for only certain properties of this object?
clean, and also renameslastWillMessage.cleanin the ES6 object then it will. If you don't then it won't. It has no idea what properties some other module is expecting or how that other thing will handle their presence or absence. You have to read the MQTT docs to figure that out. The only thing ES6's shorthand is doing for you here is that if you omit the value of a property (the colon and whatever follows), it uses the value of the variable with the same name as the property.fooinstead offoo: foo. Otherwise it's like ES5 object literal syntax.