Table of Contents
1 javascript 直譯器: jupyter notebook 3/24
首先 先來看一段簡單的程式碼
var data = [3, 7, 2, 9, 1, 11]; var sum = 0; data.forEach(function(d){ sum += d; }); console.log('Sum = ' + sum);
如果 我們想要執行它 你會怎麼做?
這樣一段簡單的程式碼
以往我們需要準備一個 index.html 將 這段代碼 inline 寫進 index.html 或者是另外放入 index.js
然後在啟動一個 http server
在用 瀏覽器 打開 index.html
1.1 jupyter notebook
jupyter notebook 的環境 預設支援的語言是 Python
但其實它支援了很多種程式語言 端看使用者的需求 你可以用它來執行 R, perl, javasript 等其他語言
在 code cell 當中以
%%javascript
作為開頭
jupyter notobook 就會將這段代碼 當作 javascript 送給瀏覽器 執行
%%javascript var data = [3, 7, 2, 9, 1, 11]; var sum = 0; data.forEach(function(d){ sum += d; }); console.log('Sum = ' + sum);
1.2 local var, global var
%%javascript var a = 1; window.a = a;
%%javascript console.log(a);