Write Concise Declarative Functions with ES6

// change code below this line
const bicycle = {
  gear: 2,
  setGear(newGear) {
    "use strict";
    this.gear = newGear;
    return newGear;
  },
 
};
// change code above this line
bicycle.setGear(48);
console.log(bicycle.gear);
var {gear}=bicycle;
console.log(gear) // returns 48
// The question is whether could destruct like "var {setGear}=bicycle;" using and getting results of newGear

…actually it doesn’t work . could any one here help me to do ths.

I am not sure what exactly you want to achieve. If you destruct the method and invoke it like a general function, it won’t behave normally because the this will default to either undefined or the global object (depending on whether you use “use strict”), not the bicycle object which has the property gear.

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make easier to read.

See this post to find the backtick on your keyboard. The “preformatted text” tool in the editor (</>) will also add backticks around text.

Note: Backticks are not single quotes.

markdown_Forums