--- id: 587d7b8b367417b2b2512b50 title: Write Concise Declarative Functions with ES6 challengeType: 1 videoUrl: '' localeTitle: Escrever funções declarativas concisas com o ES6 --- ## Description
Ao definir funções dentro de objetos no ES5, precisamos usar a function palavra-chave da seguinte forma:
const pessoa = {
nome: "Taylor",
sayHello: function () {
return "Olá! Meu nome é $ {this.name} .`;
}
};
Com ES6, você pode remover a palavra-chave da function e dois pontos ao definir funções em objetos. Aqui está um exemplo dessa sintaxe:
const pessoa = {
nome: "Taylor",
diga olá() {
return "Olá! Meu nome é $ {this.name} .`;
}
};
## Instructions
Refatorar a função setGear dentro da bicycle do objeto para usar a sintaxe abreviada descrita acima.
## Tests
```yml tests: - text: Expressão de função tradicional não foi usada. testString: 'assert(!getUserInput("index").match(/function/),"Traditional function expression was not used.");' - text: setGear é uma função declarativa. testString: 'assert(typeof bicycle.setGear === "function" && getUserInput("index").match(/setGear\s*\(.+\)\s*\{/), "setGear is a declarative function.");' - text: bicycle.setGear(48) altera o valor da gear para 48. testString: 'assert((new bicycle.setGear(48)).gear === 48, "bicycle.setGear(48) changes the gear value to 48.");' ```
## Challenge Seed
```js // change code below this line const bicycle = { gear: 2, setGear: function(newGear) { "use strict"; this.gear = newGear; } }; // change code above this line bicycle.setGear(3); console.log(bicycle.gear); ```
## Solution
```js // solution required ```