您现在的位置是:首页 > 电脑技术查询 > web开发

这段代码的执行结果很诡异,还望高手不吝赐教!该怎么处理

编辑:chaxungu时间:2022-10-02 23:15:33分类:web开发

这段代码的执行结果很诡异,还望高手不吝赐教!
JScript codefunction 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 codeglobalglobal methodglobal method return
呢,还望高手不吝赐教,正确的打印结果不应该是
JScript codeglobal methodglobalglobal 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>