2015-07-21 251 views
1

當我走到低谷客戶通道代碼(phoenix.js文件中),我看到它使用ES6。示例代碼:鳳凰渠道polyfills

let chan = socket.chan("rooms:123", {token: roomToken}) 
//  chan.on("new_msg", msg => console.log("Got message", msg)) 
//  $input.onEnter(e => { 
//  chan.push("new_msg", {body: e.target.val}) 
//   .receive("ok", (message) => console.log("created message", message)) 
//   .receive("error", (reasons) => console.log("create failed", reasons)) 
//   .after(10000,() => console.log("Networking issue. Still waiting...")) 

this.onError(reason => { 
     this.socket.log("channel", `error ${this.topic}`, reason) 
     this.state = CHAN_STATES.errored 
     this.rejoinTimer.setTimeout() 
    }) 

這意味着它不會在IE和Safari本機運行(至少)。我不應該使用某種polyfills? 什麼是最好的方法/ polyfill? 此外,我認爲polyfills蓋類/ /出租的印象......但沒有箭頭的功能/新字符串插值。我應該改變這些嗎?

回答

3

由於ES6增加了新的語法的語言,就沒有辦法來填充工具箭頭的功能。

然而,創建一個新的應用程序時,鳳凰安裝一個名爲Brunch庫,用於合併資產。它包括Babel的包裝,將transpile ES6爲JavaScript將在瀏覽器中運行。

如果你看priv/static/app.js(編譯的輸出)而不是web/static/app.js(源),那麼你會看到它沒有新的ES6語法。如果您使用某些功能,您可能會發現

一兩件事,那麼你可能需要包括babel-polyfill.js你可以在https://babeljs.io/docs/advanced/caveats/

這是在鳳凰城0.10.0介紹瞭解,您可以在公告閱讀更多關於它發佈http://www.phoenixframework.org/v0.14.0/blog/phoenix-0100-released-with-assets-handling-generat

+0

明白了。再次感謝你。 –