Skip to content

Commit 73864ea

Browse files
authored
Merge pull request #122 from Sara-Elsayed/objects
second edit to objects article
2 parents 9328c0c + 9b1a867 commit 73864ea

1 file changed

Lines changed: 29 additions & 28 deletions

File tree

1-js/04-object-basics/01-object/article.md

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -322,77 +322,78 @@ alert(obj.__proto__); // [object Object] - the value is an object, didn't work a
322322

323323
## فحص الكينونة, "in" معامل
324324

325-
A notable feature of objects in JavaScript, compared to many other languages, is that it's possible to access any property. There will be no error if the property doesn't exist!
325+
ميزة ملحوظة للكائنات في الجافا اسكريبت ، مقارنة بالعديد من اللغات الأخرى ، هي أنه من الممكن الوصول إلى أي خاصية. لن يكون هناك خطأ إذا كانت الخاصية غير موجودة!
326326

327-
Reading a non-existing property just returns `undefined`. So we can easily test whether the property exists:
327+
328+
قراءة خاصية غير موجودة تُرجع فقط "غير محدد". لذا يمكننا بسهولة اختبار ما إذا كانت الخاصية موجودة:
328329

329330
```js run
330331
let user = {};
331332

332-
alert( user.noSuchProperty === undefined ); // true means "no such property"
333+
alert( user.noSuchProperty === undefined ); // "تحقق هذه الموازنة يشير إلى "عدم وجود الخاصية
333334
```
334335

335-
There's also a special operator `"in"` for that.
336+
يوجد أيضا مُعامل خاصة `"in"` لفحص تواجد أي خاصية.
336337

337338
The syntax is:
338339
```js
339340
"key" in object
340341
```
341342

342-
For instance:
343+
مثلاً:
343344

344345
```js run
345346
let user = { name: "John", age: 30 };
346347

347-
alert( "age" in user ); // true, user.age exists
348-
alert( "blabla" in user ); // false, user.blabla doesn't exist
348+
alert( "age" in user ); // true, user.age موجود
349+
alert( "blabla" in user ); // false, user.blabla غير موجود
349350
```
350351

351-
Please note that on the left side of `in` there must be a *property name*. That's usually a quoted string.
352+
يرجى ملاحظة أنه في الجهة اليسرى من `in` يجب أن يكون هناك *اسم خاصية*. يكون عادة نصًا بين علامتي تنصيص.
352353

353-
If we omit quotes, that means a variable, it should contain the actual name to be tested. For instance:
354+
إذا حذفنا علامات التنصيص ، فهذا يعني متغيرًا ، يجب أن يحتوي على الاسم الفعلي المراد اختباره. على سبيل المثال:
354355

355356
```js run
356357
let user = { age: 30 };
357358

358359
let key = "age";
359-
alert( *!*key*/!* in user ); // true, property "age" exists
360+
alert( *!*key*/!* in user ); // true, خاصية "age" موجودة
360361
```
361362
362-
Why does the `in` operator exist? Isn't it enough to compare against `undefined`?
363+
لماذا يوجد المعامل `in`? أليس من الكافي المقارنة مقابل `undefined`?
363364
364-
Well, most of the time the comparison with `undefined` works fine. But there's a special case when it fails, but `"in"` works correctly.
365+
حسناً, في معظم الأحيان المقارنة ب `undefined` تكون جيدة. ولكن هناك حالة خاصة عندما تفشل, لكن `"in"` تعمل بشكل صحيح.
365366
366-
It's when an object property exists, but stores `undefined`:
367+
يحدث ذلك عند وجود خاصية داخل كائن ، ولكنها تخزن قيمة `undefined`:
367368
368369
```js run
369370
let obj = {
370371
test: undefined
371372
};
372373

373-
alert( obj.test ); // it's undefined, so - no such property?
374+
alert( obj.test ); // تعطي undefined, لذلك - ألا توجد هذه الخاصية؟
374375

375-
alert( "test" in obj ); // true, the property does exist!
376+
alert( "test" in obj ); // true, الخاصية موجودة بالفعل!
376377
```
378+
379+
في الكود السابق, الخاصية `obj.test` موجودة بالفعل. لذا معامل `in`يعمل بشكل صحيح.
377380
378-
In the code above, the property `obj.test` technically exists. So the `in` operator works right.
379-
380-
Situations like this happen very rarely, because `undefined` should not be explicitly assigned. We mostly use `null` for "unknown" or "empty" values. So the `in` operator is an exotic guest in the code.
381+
مواقف كهذه تحدث نادراً, لأن `undefined` لا ينبغي تعيينها بشكل ذاتي. عادة ما نستخدم `null` ل "unknown" أو "empty" قيم . لذا معامل `in` يعتبر ضيفاً غريباً في الكود.
381382
382383
383384
## The "for..in" loop
384385
385-
To walk over all keys of an object, there exists a special form of the loop: `for..in`. This is a completely different thing from the `for(;;)` construct that we studied before.
386+
للمرور على كل مفاتيح الكائن, يوجد شكل خاص آخر للحلقة loop: `for..in`. هذه الحلقة مختلفة تمامًا عما درسناه سابقًا، أي الحلقة `for(;;)`.
386387
387-
The syntax:
388+
طريقة الكتابة في الكود:
388389
389390
```js
390391
for (key in object) {
391-
// executes the body for each key among object properties
392+
//يتنفذ ما بداخل الحلقة لكل مفتاح ضمن خاصيات الكائن
392393
}
393394
```
394395
395-
For instance, let's output all properties of `user`:
396+
مثلاً, لنطبع جميع خاصيات الكائن `user`:
396397
397398
```js run
398399
let user = {
@@ -402,20 +403,20 @@ let user = {
402403
};
403404

404405
for (let key in user) {
405-
// keys
406+
// المفاتيح
406407
alert( key ); // name, age, isAdmin
407-
// values for the keys
408+
// قيم المفاتيح
408409
alert( user[key] ); // John, 30, true
409410
}
410411
```
411412
412-
Note that all "for" constructs allow us to declare the looping variable inside the loop, like `let key` here.
413+
لاحظ أن جميع تراكيب "for" تتيح لنا تعريف متغير التكرار بِداخل الحلقة، مثل `let key` في المثال السابق,.
413414
414-
Also, we could use another variable name here instead of `key`. For instance, `"for (let prop in obj)"` is also widely used.
415+
أيضاً, يمكننا استخدام اسم متغير آخر بدلا من `key`. مثلا, `"for (let prop in obj)"` مستخدم أيضاَ بكثرة.
415416
416-
### Ordered like an object
417+
### الترتيب مثل الكائنات
417418
418-
Are objects ordered? In other words, if we loop over an object, do we get all properties in the same order they were added? Can we rely on this?
419+
هل الكائنات مرتبة? بمعنى آخر, إن تنقلنا في حلقة خلال كائن, هل نحصل على جميع الخاصيات بنفس الترتيب الذي أُضيفت به؟ وهل يمكننا الاعتماد على هذا؟
419420
420421
The short answer is: "ordered in a special fashion": integer properties are sorted, others appear in creation order. The details follow.
421422

0 commit comments

Comments
 (0)