Can you alter a Javascript function after declaring it?

前端 未结 12 798
佛祖请我去吃肉
佛祖请我去吃肉 2020-11-28 22:10

Let\'s say I have var a = function() { return 1; }. Is it possible to alter a so that a() returns 2? Perhaps by editing a

12条回答
  •  隐瞒了意图╮
    2020-11-28 22:32

    var a = function() { return 1; }
    alert(a()) // 1
    a = function() { return 2; }
    alert(a()) // 2
    

    technically, you're losing one function definition and replacing it with another.

提交回复
热议问题