日期:2014-05-16  浏览次数:20359 次

这段代码的执行结果很诡异,还望高手不吝赐教!
JScript code

function base() {
    this.member = "global";
    this.method = function() {
        console.log("global method");
        return "global method return";
    };
}


(function extend() {
    base.call(this);
    console.log(this.member);
    console.log(this.method());
})();



其打印结果为什么会是:
JScript code

global
global method
global method return


呢,还望高手不吝赐教,正确的打印结果不应该是
JScript code

global method
global
global method return



吗?

------解决方案--------------------
HTML code


<script type="text/javascript">  
            function base() {
                this.member = "global";
                this.method = function() {
                    console.log("global method");
                    return "global method return";
                };
            }

            (function extend() {
                base.call(this);
                console.log(this.member);   //这句输出global ,因为base函数的this.member 就是 "global";
                console.log(this.method());  //这句输出 global method  global method return   //lz你可以把这句注释掉就清楚了,
            })();
        </script>