Message from JavaScript discussions

April 2019

— const pluck = keys => obj =>
keys.length === 0
? []
: [
obj[keys[0]],
...pluck(keys.slice(1))(obj)
];

const newSim = new Sim(...pluck([
'name',
'surname',
'gender'
]));

Message permanent page

— 

Or you can just allow an object option to Sim:

constructor(firstName, lastName, gender, photo, neat, outgoing, active, playful, nice) {

if (
firstName &&
typeof firstName === 'object'
) {
Object.assign(this, firstName);
return this;
}
// rest of normal code

— Then you can do:

new Sim('John', 'Doe');
new Sim({ firstName: 'John', lastName: 'Doe' });

— And both would work

— And object option would make much more sense too

— new Sim({
name: { first: 'John', last: 'Doe' },
gender: 'male',
photo: ...,
personality: {
neat: true,
outgoing: true
}
});

Message permanent page

— The above makes much more sense than:
new Sim(
'John',
'Doe',
'male',
...,
true,
true);

— This is advanced stuff

— No no

— Very simple :D

— How are you getting the values from the object, destructing?

— Could do, but don't have to