Record the interview questions with closing the package

function fun(n,o) {
    
    
  console.log(o)
  return {
    
    
    fun:function(m){
    
    
      return fun(m,n);
    }
  };
}
var a = fun(0);  a.fun(1);  a.fun(2);  a.fun(3);//undefined,?,?,?
var b = fun(0).fun(1).fun(2).fun(3);//undefined,?,?,?
var c = fun(0).fun(1);  c.fun(2);  c.fun(3);//undefined,?,?,?
//问:三行a,b,c的输出分别是什么?
function Foo() {
    
    
    getName = function () {
    
     alert (1); };
    return this;
}
Foo.getName = function () {
    
     alert (2);};
Foo.prototype.getName = function () {
    
     alert (3);};
var getName = function () {
    
     alert (4);};
function getName() {
    
     alert (5);}

//答案:
Foo.getName();//2
getName();//4
Foo().getName();//1
getName();//1
new Foo.getName();//2
new Foo().getName();//3
new new Foo().getName();//3

Analysis: The
first question is that the fun from return is the outermost fun

Analysis of the second question
Insert picture description here

For more details, please see
https://blog.csdn.net/deqi4006/article/details/102445587

Guess you like

Origin blog.csdn.net/Beth__hui/article/details/114128215