首页 > 试题广场 >

这段代码执行后,打印的结果是什么,为什么会是这样? ```j

[问答题]
这段代码执行后,打印的结果是什么,为什么会是这样?
             

```js
function test() {           

    getName = function() { 
        Promise.resolve().then(() => console.log(0)); 
        console.log(1);               

    };

    return this; 
}
test.getName = function() { 
     setTimeout(() => console.log(2), 0); 
     console.log(3);               

};
test.prototype.getName = function() {    

     console.log(4); 
};       
var getName = function() { 
     console.log(5);             

};
function getName() {

     console.log(6); 
}      
      
test.getName(); 
getName(); 
test().getName(); 
getName();  
new test.getName();
new test().getName();
new new test().getName();
```

这道题你会答吗?花几分钟告诉大家答案吧!