AcollectionofcommandsandES6-readysnippetsforoptimizingJavascriptandTypescriptdevelopmentproductivity.
CommandsUsethefollowingkeymapstospeedupyourdevelopment.Youcanquicklyterminatelineswithsemicolonsormanipulateblocksofcodewithease.
EndLineCTRL-;Terminatesthecurrentlinewithasemicolon.
EndLinewithacommaCTRL-,Terminatesthecurrentlinewithacomma(greatforobjectliterals).
EndNewLineCTRL-ENTERTerminatesthecurrentlinewithacolonorsemicolon,followedwithanewline.Acommaisinsertedwhenthecursorisinsideanobjectliteral,otherwiseasemicolonisinserted.
EasyBlocksCTRL-BCreatesastatementblock{...}withtheselectedtextplacedinsideandproperlyindented.Iftheselectionisalreadywrappedwithablock,theblockisremovedanditscontentisunindented.
SnippetsSnippetsareoptimizedtobeshortandeasytoremember.Somesnippetsare"chainable"andrenderdifferentlywhenprecededbya".".
Forexample,.ferendersachain-friendlyversionofthe"forEach"snippet,whileferendersafullcodeblock.
Declarationsv⇥varstatementvar${1:name}v=⇥varassignmentvar${1:name}=${2:value}l⇥letstatementlet${1:name}l=⇥letassignmentlet${1:name}=${2:value}co⇥conststatementconst${1:name}co=⇥constassignmentconst${1:name}=${2:value}FlowControlif⇥ifstatementif(${1:condition}){${0}}el⇥elsestatementelse{${0}}ife⇥elsestatementif(${1:condition}){${0}}else{}ei⇥elseifstatementelseif(${1:condition}){${0}}fl⇥forloopfor(let${1:i}=0,${2:len}=${3:iterable}.length;${1:i}<${2:len};${1:i}++){${0}}fi⇥forinloopfor(let${1:key}in${2:source}){if(${2:source}.hasOwnProperty(${1:key})){${0}}}fo⇥forofloop(ES6)for(let${1:key}of${2:source}){${0}}wl⇥whileloopwhile(${1:condition}){${0}}tc⇥try/catchtry{${0}}catch(${1:err}){}tf⇥try/finallytry{${0}}finally{}tcf⇥try/catch/finallytry{${0}}catch(${1:err}){}finally{}sw⇥switchcaseswitch(${1:expr}){case${2:value}:return$0;default:return;}Functionsf⇥anonymousfunctionfunction(${1:arguments}){${0}}fn⇥namedfunctionfunction${1:name}(${2:arguments}){${0}}iife⇥immediately-invokedfunctionexpression(IIFE)(function(${1:arguments}){${0}})(${2});fa⇥functionapply${1:fn}.apply(${2:this},${3:arguments})fc⇥functioncall${1:fn}.call(${2:this},${3:arguments})fb⇥functionbind${1:fn}.bind(${2:this},${3:arguments})af⇥arrowfunction(ES6)(${1:arguments})=>${2:statement}afb⇥arrowfunctionwithbody(ES6)(${1:arguments})=>{\t${0}}gf⇥generatorfunction(ES6)function*(${1:arguments}){${0}}gfn⇥namedgeneratorfunction(ES6)function*${1:name}(${1:arguments}){${0}}Iterablesseq⇥sequenceof0..n[...Array(${1:length}).keys()]${0}fe⇥forEachloop(chainable)${1:iterable}.forEach((${2:item})=>{${0}});map⇥mapfunction(chainable)${1:iterable}.map((${2:item})=>{${0}});reduce⇥reducefunction(chainable)${1:iterable}.reduce((${2:previous},${3:current})=>{${0}}${4:,initial});filter⇥filterfunction(chainable)${1:iterable}.filter((${2:item})=>{${0}});find⇥ES6findfunction(chainable)${1:iterable}.find((${2:item})=>{${0}});Objectsandclassesc⇥class(ES6)class${1:name}{constructor(${2:arguments}){${0}}}cex⇥childclass(ES6)class${1:name}extends${2:base}{constructor(${2:arguments}){super(${2:arguments});${0}}}ctorclassconstructor(ES6)constructor(${1:arguments}){super(${1:arguments});${0}}:⇥key/valuepairJavascript:
${1:key}:${2:'value'}JSON:
"${1:key}":${2:"value"}m⇥method(ES6syntax)${1:method}(${2:arguments}){${0}}get⇥getter(ES6syntax)get${1:property}(){${0}}
评论