728x90
반응형
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// fibonacci.js | |
class FibonacciSequence { | |
[Symbol.iterator]() { | |
let a = 0, b = 1; | |
return { | |
next() { | |
let rval = { value: b, done: false }; | |
b += a; | |
a = rval.value; | |
return rval; | |
} | |
}; | |
} | |
} | |
const fib = new FibonacciSequence(); | |
let i = 0; | |
for(let n of fib) { | |
console.log(n); | |
if(++i > 9) | |
break; | |
} |
728x90
반응형
'Javascript' 카테고리의 다른 글
non TDZ (0) | 2018.11.22 |
---|---|
closure (0) | 2018.11.22 |
iteration from 'Learning Javascript' (0) | 2018.11.08 |
화살표 함수 Arrow function of javascript (0) | 2018.09.28 |
javascript require 예제 (0) | 2018.08.23 |