다시 말하지만, 분기 예는 레거시 시맨틱이 해결해야 하는 일반적인 처리 목록에 맞지 않지만 레거시 시맨틱은 현재 처리 방법을 알려 준다(이전 엔진에서는 이러한 방식으로 처리되지 않을 수 있다). 함수 범위에서 doSomething var 스타일 변수, 마지막에 doSomething 호출이 작동한다. "use strict";를 사용하지 않고 함수 선언 전후에 로깅을 사용하여 예를 다시 살펴보겠다. 코드 3-5를 불러서 실행하자.

    코드 3-5 블록 안의 함수 선언: 웹 호환성–func-decl-block-web-compat.js

    function branching(num) {
        console.log("num = " + num + ", typeof doSomething = " + typeof doSomething);
        if (num < 0.5) {
            console.log("true branch, typeof doSomething = " + typeof doSomething);
            function doSomething() {
                console.log("true");
            }
            console.log("end of true block");
        } else {
            console.log("false branch, typeof doSomething = " + typeof doSomething);
            function doSomething() {
                console.log("false");
            }
            console.log("end of false block");
        }
        doSomething();
    }
    branching(Math.random());
    신간 소식 구독하기
    뉴스레터에 가입하시고 이메일로 신간 소식을 받아 보세요.