烘焙函数定义以防止 JavaScript 中的重载

Bake in function definition to prevent overloading in JavaScript

// Change the following function:
function sayHello(name) {
  return "Hello " + name;
}

// Not possible to change the code below
console.log(sayHello("John"));

function sayHello(name) {
  return "Hola " + name;
}

以下代码的输出将是Hola John

是否可以修改函数 sayHello 的第一个定义,使输出为 Hello John?也许有一种方法可以修改函数 'inline' 定义在它被调用的地方,然后再被覆盖...?

函数 sayHello 在第一次通过时声明它。然后在第二遍,你可以 "rebind/overwrite" 定义 sayHello

// Change the following function:
sayHello = function(name) {
  return "Hello " + name;
}

// Not possible to change the code below
console.log(sayHello("John"));

function sayHello(name) {
  return "Hola " + name;
}