How to make function parameter constant in JavaScript?

后端 未结 8 1081
野的像风
野的像风 2020-12-13 12:43

What I want to do is to use as many immutable variables as possible, thus reducing the number of moving parts in my code. I want to use \"var\" and \"let\" only when it\'s n

8条回答
  •  悲&欢浪女
    2020-12-13 13:29

    function wrapper(i){
        const C=i
        return new Function("a","b", "return a+b+"+C)    
    }
    
    f100 = wrapper(100) //ƒ anonymous(a,b/*``*/) {return a+b+100} 
    f100(1,2) //OUTPUT 103
    
    f200 = wrapper(200) //ƒ anonymous(a,b/*``*/) {return a+b+200} 
    f200(1,2) //OUTPUT 203
    

提交回复
热议问题