编辑代码

/* 

    闭包

 */



let n = 1

function fo() {
    n++
    function foo() {
        console.log(n)
    }
    return foo
}

const a = fo()

a()
a()


let ww = ' hhhhh '

function info() {
    let ww = 'qqq'
    console.log(this.www)
    function infoo() {
        console.log(this.ww)
    }
    return infoo
}

info()

let tt = 'tt'
console.log(tt)

let ff
console.log(ff)
// console.log(rr)


// 手写一个new

function cre() {

    let obj = {}

    let [first, ...arg] = arguments

    obj.__proto__ = first.prototype

    let result = first.apply(obj, arg)

    return result ? result : obj





}

/* 
    手写深拷贝

 */

function deepLoop(obj) {

    let foo = Array.isArray(data) ? [] : {}

    for (let i in obj) {
        if (obj.hasOwnProperty(i)) {
            foo[i] = typeof obj[i] === 'object' ? deepLoop(obj[i]) : obj[i]
        }
    }

    return foo

}




/* 

手写防抖
思路:一段时间内执行多次,清空之前的,只执行最后一次

 */


function debounce(fn, wait) {
    var timer = null;


    // 如果此时存在定时器的话,则取消之前的定时器重新记时
    if (timer) {
        clearTimeout(timer);
        timer = null;
    }



    time = setTimeout(() => {



    }, wait)
}


for (let i = 0; i < 5; i++) {
    setTimeout(() => {
        console.log(i)
    }, 0)
}



function fn(num) {
    let zhishuarr = []
    for (let i = 0; i < num; i++) {
        for (let j = 1; j < i / 2 + 1; j++) {
            if (i % j != 0) {
                 zhishuarr.push(i)
                 break
            } 
        }
    }
    return zhishuarr
}


console.log(fn(200))



setTimeout(()=>{
    console.log(arguments)
},0)