Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
-
@ElectroArchiver I’m not sure how this would be useful in the context of destructoring, but since variadic parameters are ultimately arrays in Swift, you could assign them to a variable as well.
-
I like array constructuring in javascript:
let arr1 = [a, b, c]
let arr2 = [1,...arr1,3] -
-
@useVim Where is that from?
( FSS devrant doesn't keep line spacing / indentation, fuck )
Also I can't not refactor that:
const { referralCode , email , role , name , _id } =
request.auth.credentials.UserSession[0].user;
const userData = {
email , role , name ,
referral : referralCode ,
userId : _id
} -
@ElectroArchiver but then you are relying on the order of the properties in the user object?
This sounds dangerous/unsafe for various reasons.
Edit: Oh they are probably mapped by name. That’s why you create a second object afterwards. -
@Lensflare JS has destructuring for arrays as well for objects, here with objects, the order doesn't matter.
-
useVim21422y@ElectroArchiver
const [{ user }] = request.auth.credentials.UserSession;
user.email
user.role
...
The TRICK! -
@useVim Also if you're just renaming those 2 keys and the remaining stuff is all that's in user, you could do:
const { referralCode : referral , _id : userId , ... args } = user;
const userData = { referral , userId , ...args }
array destructuring people. please!
rant