Cast expression to variable


#1

Hi, in webstorm you can put your cursor on an expression and hit ctrl-alt-v and it will pull that expression out and give you a var for it so something like this
const foo = myArray.map(x=>x.firstName);
would give you
const myVar = x=>x.firstName;
const foo = myArray.map(myVar);

is there anything like this is atom? also you can do something similar with a function. Highlight a block of code and ctrl-alt-v ( i think ) and it will create a function that returns that block and insert the call into your code.

Thanks for the help
R


#2

I haven’t seen anything like this, but one of the easiest things to do in Atom is to code a keybinding that extracts the latest selection, edits the text, moves the cursor to the beginning of the line, and inserts the changed text. For extra robustness, you can make it return and do nothing if there are multiple cursors.