
我正在使用 node ,嘗試以編程方式構建 jupyter 筆記本。我正在嘗試創建一個將構建筆記本“代碼”型別單元的函式。在 repl 作業后,我有:
function codeCell(arr =>
`{
cell_type: 'code',
execution_count: null,
metadata: { tags: [] },
outputs: [],
source: [${arr}]
}`
);
正如您在螢屏截圖中看到的那樣,我收到了一個識別符號預期錯誤。我究竟做錯了什么?
uj5u.com熱心網友回復:
function codeCell(arr =>
您開始在函式定義的引數串列中定義箭頭函式,這是無效的語法。
要么寫
function codeCell(arr) {
return `{
cell_type: 'code',
execution_count: null,
metadata: { tags: [] },
outputs: [],
source: [${arr}]
}`;
}
或者,如果您想使用箭頭函式語法:
const codeCell = (arr) => `{
cell_type: 'code',
execution_count: null,
metadata: { tags: [] },
outputs: [],
source: [${arr}]
}`;
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/453575.html
標籤:javascript 节点.js
