
理论原理
cunlim
这个作者很懒,什么都没留下…
展开
-
js 模拟构造函数隐式步骤
正常的 function Car(color) { // var this = {}; this.name = 'BMW'; this.color = color; // return this } var car1 = new Car('red'); // 当函数执行前加 new 关键字,则在函数隐式执行两个步骤。 // 此隐式 this 不可写成显示,不然报错: // test.html:13 Uncaught SyntaxError: Unexpected token 'this' .原创 2020-06-17 21:55:30 · 179 阅读 · 0 评论 -
js 闭包
要求:执行闭包函数10次,打印0~9 闭包错误:结果得到十个10。 原因是比如arr[3] = function () {console.log(i)} 中的函数体没被执行,变量 i 还没变现成具体的数。 等到myArrj执行的时候 i 才会访问[[scope]]链, 而此时每个数组访问的是:test函数里的循环完成后已经变成了10的 i。 function test() { var arr =...原创 2019-12-31 00:55:29 · 132 阅读 · 0 评论