그냥 단순히 finally에 return이 있으면 finally 없으면 try나 catch구문의 return
이라고 이해해도 사용은 가능 하지만
실제로는 결정 과정이 좀 복잡하다.
According to ECMA-262 (5ed, December 2009), in pp. 96:
The production TryStatement : try Block Finally is evaluated as follows:
- Let B be the result of evaluating Block.
- Let F be the result of evaluating Finally.
- If F.type is normal, return B.
- Return F.
And from pp. 36:
The Completion type is used to explain the behaviour of statements (break, continue, return and throw) that perform nonlocal transfers of control. Values of the Completion type are triples of the form (type, value, target), where type is one of normal, break, continue, return, or throw, value is any ECMAScript language value or empty, and target is any ECMAScript identifier or empty.
It's clear that return false would set completion type of finally as return, which cause try ... finally to do 4. Return F.
참조: https://stackoverflow.com/questions/3837994/why-does-a-return-in-finally-override-try
'javascript' 카테고리의 다른 글
javascript] bind vs wrapper (0) | 2018.11.17 |
---|---|
callback 패턴 함수를 await로 쓰는 방법 (0) | 2018.05.01 |
nodeJs require (0) | 2018.04.13 |
함수형 프로그래밍 : reduce (0) | 2018.04.07 |
promise 대신 async, await를 사용하자 (0) | 2018.03.22 |