qappleh / Interview

我是追梦赤子心,公众号「深圳湾码农」的作者,某上市集团公司高级前端开发,深耕前端领域多年,每天攻破一道题,带你从0到1系统构建web全栈完整的知识体系!
https://github.com/qappleh/Interview
1.14k stars 95 forks source link

Day370:代码输出题,考察构造函数、原型链、函数和变量提升等,代码如下: #373

Open qappleh opened 3 years ago

qappleh commented 3 years ago
function Fun() {
    getName = function () {
       console.log(1);
    };
    return this;
}

var getName

function getName () {
    console.log(5);
}

Fun.getName = function () {
    console.log(2);
}

Fun.prototype.getName = function () {
    console.log(3);
}

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

请写出以下代码的输出结果:

getName();

Fun.getName();

Fun().getName();

getName();

new Fun.getName();

new Fun().getName();

new new Fun().getName();