2014-07-03 12 views
6

Sono nuovo di coffeescript. C'è un modo per prendere queste tre linee per impostare la rotazione e realizzare la stessa cosa, come faresti con Python disimballando una tupla?coffeescript come decomprimere come "tuple" in python

@cosines = [0,1,0] 
@branch.rotation.x = Math.asin(@cosines.x) 
@branch.rotation.y = Math.asin(@cosines.y) 
@branch.rotation.z = Math.asin(@cosines.z) 

risposta

7

Questo è il codice migliore che potrei trovare.

@cosines = [0,1,0] 
rot = @branch.rotation 
[rot.x, rot.y, rot.z] = [Math.asin(c) for c in @cosines] 

Il disimballaggio destructuring è lo stesso come in Python, ma con parentesi quadre.

+0

Impressionante, grazie – nino