首页 > 试题广场 >

这段代码执行后,打印的结果是什么,为什么会是这样? ```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();
```
//主线
//3 6 1 1 3 4 4
//定时器 宏任务队列
//2 0 0 2
发表于 2025-12-09 17:54:34 回复(0)