mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-04-12 01:00:13 -04:00
2.1 KiB
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
};