math.js函數
export function* getFibo()get
{generator
let a = 1;io
let b = 1;console
yield a;function
yield b;import
while (true) {yield
let next = a + b;引用
a = b;im
b = next;
yield next;
}
}
export function add(a,b)
{
return a+b;
}
index.js
{ } 內容必須與 math定義的值同樣,固然也能夠用 as
import {add,getFibo} from "./tool/math.js"
let generator = getFibo;
for (let i = 1; i < 10; i++) {
let result = generator().next().value;
console.log(`fibo:${i} =${result}`);
}
console.log(add(1,2));
含有 default 導出 export
math.js
export default function* getFibo()
{
let a = 1;
let b = 1;
yield a;
yield b;
while (true) {
let next = a + b;
a = b;
b = next;
yield next;
}
}
index.js
import myFibo from "./tool/math.js"
let generator = myFibo;
for (let i = 1; i < 10; i++) {
let result = generator().next().value;
console.log(`fibo:${i} =${result}`);
}