Files
freeCodeCamp/curriculum/challenges/arabic/02-javascript-algorithms-and-data-structures/es6/write-concise-object-literal-declarations-using-object-property-shorthand.md
freeCodeCamp's Camper Bot e6b05ee25d chore(i18n,learn): processed translations (#54537)
Co-authored-by: Naomi <nhcarrigan@gmail.com>
2024-04-26 12:26:37 +07:00

2.1 KiB

id, title, challengeType, forumTopicId, dashedName
id title challengeType forumTopicId dashedName
587d7b8a367417b2b2512b4f أكتب إعلانات واضح للكائن (Object) باستعمال خاصية تختصر الكائن 1 301225 write-concise-object-literal-declarations-using-object-property-shorthand

--description--

يضيف ES6 بعض الدعم اللطيف لتعريف الكائنات بسهولة.

ضع في اعتبارك الكود التالي:

const getMousePosition = (x, y) => ({
  x: x,
  y: y
});

يكون getMousePosition وظيفة (function) بسيطة ترجع كائن (object) يحتوي على خاصيتين. يوفر ES6 بناء الجملة السهل لإزالة الازدواجية في كتابة x: x. يمكنك ببساطة كتابة x مرة واحدة، وسيتم تحويله إلىx: x (أو ما يعادلها من شيء) خلف الكواليس. إليك نفس الوظيفة (function) من الأعلى, معاد كتابتها لاستخدام هذا التشكيل (syntax) الجديد:

const getMousePosition = (x, y) => ({ x, y });

--instructions--

استخدم خاصية الكائن المختصرة مع حروف الكائن لإنشاء كائن بخصائص name, و age, و gender.

--hints--

createPerson("Zodiac Hasbro", 56, "male") يجب أن يرجع {name: "Zodiac Hasbro", age: 56, gender: "male"}.

assert.deepEqual(
  { name: 'Zodiac Hasbro', age: 56, gender: 'male' },
  createPerson('Zodiac Hasbro', 56, 'male')
);

يجب أن لا يستخدم الكود key:value.

assert(!__helpers.removeJSComments(code).match(/:/g))

--seed--

--seed-contents--

const createPerson = (name, age, gender) => {
  // Only change code below this line
  return {
    name: name,
    age: age,
    gender: gender
  };
  // Only change code above this line
};

--solutions--

const createPerson = (name, age, gender) => {
  // Only change code below this line
  /*return {
    name: name,
    age: age,
    gender: gender
  };*/
  return {
    name,
    age,
    gender
  };
  // Only change code above this line
};