fix: converted single to triple backticks10 (#36237)

This commit is contained in:
Randell Dawson
2019-06-20 14:53:53 -07:00
committed by Tom
parent da6bd27eec
commit 039fea8b6d
75 changed files with 1880 additions and 1655 deletions

View File

@@ -10,34 +10,37 @@ localeTitle: Dray
### الواجب الأساسي المتغير
`var names = ['neel', 'meet', 'darshan'];
var [nameOne, nameTwo, nameThree] = names;
console.log(nameOne); // "neel"
console.log(nameTwo); // "meet"
console.log(nameThree); // "darshan"
`
```
var names = ['neel', 'meet', 'darshan'];
var [nameOne, nameTwo, nameThree] = names;
console.log(nameOne); // "neel"
console.log(nameTwo); // "meet"
console.log(nameThree); // "darshan"
```
### مهمة منفصلة عن الإعلان
يمكن تعيين متغير قيمته من خلال التدمير المنفصل عن تعريف المتغير.
`var a, b;
[a, b] = [1, 2];
console.log(a); // 1
console.log(b); // 2
`
```
var a, b;
[a, b] = [1, 2];
console.log(a); // 1
console.log(b); // 2
```
### قيم افتراضية
يمكن تعيين متغير افتراضي ، في حالة أن القيمة unpacked من الصفيف غير `undefined` .
`var a, b;
[a=5, b=7] = [1];
console.log(a); // 1
console.log(b); // 7
`
```
var a, b;
[a=5, b=7] = [1];
console.log(a); // 1
console.log(b); // 7
```
### تحليل مجموعة من عاد من وظيفة
@@ -45,47 +48,52 @@ localeTitle: Dray
في هذا المثال ، تقوم `getNames()` بارجاع القيم `['neel', 'meet']` `getNames()` لها ، والتي يمكن تحليلها في سطر واحد مع destructuring.
`function getNames() {
return ['neel', 'meet'];
}
var neel, meet;
[nameOne, nameTwo] = getNames();
console.log(nameOne); // neel
console.log(nameTwo); // meet
`
```
function getNames() {
return ['neel', 'meet'];
}
var neel, meet;
[nameOne, nameTwo] = getNames();
console.log(nameOne); // neel
console.log(nameTwo); // meet
```
### تجاهل بعض القيم التي تم إرجاعها
يمكنك تجاهل قيم الإرجاع التي لا تهتم بها:
`function getNames() {
return ['neel', 'meet', 'darshan'];
}
var [nameOne, , nameThree] = getNames();
console.log(nameOne); // neel
console.log(nameThree); // darshan
`
```
function getNames() {
return ['neel', 'meet', 'darshan'];
}
var [nameOne, , nameThree] = getNames();
console.log(nameOne); // neel
console.log(nameThree); // darshan
```
يمكنك أيضًا تجاهل جميع القيم التي تم إرجاعها:
`[,,] = getNames();
`
```
[,,] = getNames();
```
### تعيين بقية صفيف إلى متغير
عند تدمير صفيف ، يمكنك فك وتعيين الجزء المتبقي منه إلى متغير باستخدام نمط الباقي:
`var [a, ...b] = [1, 2, 3];
console.log(a); // 1
console.log(b); // [2, 3]
`
```
var [a, ...b] = [1, 2, 3];
console.log(a); // 1
console.log(b); // [2, 3]
```
لاحظ أنه سيتم طرح `SyntaxError` إذا تم استخدام فاصلة زائدة على الجانب الأيسر مع عنصر راحة:
`var [a, ...b,] = [1, 2, 3];
// SyntaxError: rest element may not have a trailing comma
`
```
var [a, ...b,] = [1, 2, 3];
// SyntaxError: rest element may not have a trailing comma
```
انظر أيضا: **صفيف Destructuring** | [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment#Array_destructuring)