Files
freeCodeCamp/curriculum/challenges/arabic/02-javascript-algorithms-and-data-structures/es6/write-concise-declarative-functions-with-es6.md
2022-10-20 09:13:17 -07:00

1.7 KiB

id, title, challengeType, forumTopicId, dashedName
id title challengeType forumTopicId dashedName
587d7b8b367417b2b2512b50 Write Concise Declarative Functions with ES6 1 301224 write-concise-declarative-functions-with-es6

--description--

عند تعريف الـ functions داخل الـ objects في ES5، علينا استخدام الكلمة function كما يلي:

const person = {
  name: "Taylor",
  sayHello: function() {
    return `Hello! My name is ${this.name}.`;
  }
};

مع ES6، يمكنك إزالة كلمة function والـ colon كلياً عند تعريف الـ functions في الـ objects. إليك مثال على هذا الـ syntax:

const person = {
  name: "Taylor",
  sayHello() {
    return `Hello! My name is ${this.name}.`;
  }
};

--instructions--

قم بإعادة تشكيل الدالة setGear داخل الكائن bicycle لاستخدام الـ syntax القصير الموصوف أعلاه.

--hints--

وينبغي عدم استخدام الـ function expression التقليدي.

(getUserInput) => assert(!code.match(/function/));

setGear يجب أن تكون declarative function.

assert(
  typeof bicycle.setGear === 'function' && code.match(/setGear\s*\(.+\)\s*\{/)
);

bicycle.setGear(48) يجب أن تغير قيمة gear إلى 48.

bicycle.setGear(48);
assert(bicycle.gear === 48);

--seed--

--seed-contents--

// Only change code below this line
const bicycle = {
  gear: 2,
  setGear: function(newGear) {
    this.gear = newGear;
  }
};
// Only change code above this line
bicycle.setGear(3);
console.log(bicycle.gear);

--solutions--

const bicycle = {
  gear: 2,
  setGear(newGear) {
    this.gear = newGear;
  }
};
bicycle.setGear(3);