我想知道是否可以从函数参数
更改变量的名称例如。
function(name, content) {
var name = content;
alert(name);
}
答案 0 :(得分:0)
不,这是不可能的。您最接近的是重命名对象属性,如:
var something = { name: 'me' };
console.log('something', something);
something.content = something.name;
delete something.name;
console.log('something', something);
或作为一种功能:
const rename = (something, oldPropertyName, newPropertyName) => {
something[newPropertyName] = something[oldPropertyName];
delete something[oldPropertyName];
};