js题库全集
https://leetcode-cn.com/problemset/all/
题目一:
function U(data){ console.log(data,1); var instance = this; U = function(){ console.log(data,2); return instance; } } var U = (function(){ function U(data){ console.log(data,1); var instance = this; // 下面的代码内部函数根本没有执行 U = function(){ console.log(123); console.log(data,2); return instance; } } return U; })() var U1 = new U('u1'); console.log(U1); var U2 = new U('u2'); console.log(U2); console.log(U1 === U2);
题目二:
https://segmentfault.com/q/1010000003017312 var c = (function(){ return function a(){ a = 123; console.log(a); return a; } })() c(); a在函数中没有被赋值 这种情况下a是不能被赋值的 命名函数表达式的函数名不能重写 var c = function a() {a = 111; console.log(9)} c()//9 console.log(a);//报错 var n = function(){d = 111;console.log(9);} n();//9 console.log(d);//111 function a(){a = 111;console.log(a)} var c = a; a() //111 c() //111