Babel 没有转译 ES6 计算属性名称。它会编译其他所有内容。不知道发生了什么。使用最新版本的 cli。
var name = "John";
var age = 12;
var count = 5;
var postfix = 'age';
var person = {
name,
age,
count,
postfix,
printName(){
console.log(this.name);
this.count--;
while(this.count){
this.printName();
}
},
['print' + this.postfix]: function(){
console.log(this.age);
}
};
person.printName();
person.printAge();
通天塔输出
var name = "John";
var age = 12;
var count = 5;
var postfix = 'age';
var person = _defineProperty({
name: name,
age: age,
count: count,
postfix: postfix,
printName: function printName() {
console.log(this.name);
this.count--;
while (this.count) {
this.printName();
}
}
}, 'print' + postfix, function () { // Look here
console.log(this.age);
});