1夫啊、首先安裝 NodeJS
首先確保你的電腦已經(jīng)安裝好nodejs, 并已將其添加到環(huán)境變量中
2、添加 build system
在sublime text中依次打開(kāi)Tools -> Build System -> New Build System... 粘貼以下代碼后保存(如es6.sublime-build), 然后把Build System設(shè)成Automatic
{
"cmd": ["node", "--use-strict", "--harmony", "$file"],
"selector": "source.js"
}
在以上的build文件中(es6.sublime-build), node是執(zhí)行命令, --harmony和--use-strict是執(zhí)行參數(shù), $file是當(dāng)前文件名, 所以一次build操作實(shí)際上相當(dāng)于在命令行中執(zhí)行了node --use-strict --harmony filename. --harmony表示啟用ES Harmony features, 而這些features目前只能在strict模式下運(yùn)行, 所以需要同時(shí)添加use-strict參數(shù)(詳見(jiàn)what-is-extended-mode)
現(xiàn)在就可以在 Sublime Text 3 中編寫(xiě) ES6 代碼了,快捷鍵【Ctrl+B】執(zhí)行結(jié)果