从函数更改变量名称

时间:2016-07-12 23:52:56

标签: javascript variables

我想知道是否可以从函数参数

更改变量的名称

例如。

function(name, content) {
    var name = content;
    alert(name);
}

1 个答案:

答案 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];
};