1. 方式1
<script>
// 1.方式1:
let game = {
name: 'xxx',
up:function(){
console.log('up');
},
down: function(){
console.log('down');
}
}
let obj = {
up:Symbol(),
down:Symbol()
}
game[obj.up]=function(){
console.log('up');
}
game[obj.down]=function(){
console.log('down');
}
console.log(game);
</script>
2. 方式2
<script>
// 2.方式2:
let game = {
name: 'xxx',
[Symbol('up')]:function(){
console.log('up');
},
[Symbol('dowm')]: function(){
console.log('down');
}
}
console.log(game);
</script>