这段代码的执行结果很诡异,还望高手不吝赐教!
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());})();
globalglobal methodglobal method return
global methodglobalglobal method return
<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>