Skip to content

Commit 344f8d8

Browse files
committed
merging all conflicts
2 parents 58381bc + 445bda3 commit 344f8d8

8 files changed

Lines changed: 242 additions & 8 deletions

File tree

1-js/02-first-steps/09-comparison/article.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,13 @@
99
- يساوي: `a == b` ، يرجى ملاحظة أن علامة المساواة المزدوجة` = `تعني اختبار المساواة ، في حين أن كلمة واحدة` a = b` تعني تعيين أو مساواة .
1010
- لا تساوي. في الرياضيات يكون الترميز <code>&ne;</code> ،لكن في JavaScript تكتب هكذا <code>a != b</code>.
1111

12+
<<<<<<< HEAD
1213
في هذه المقالة سنتعلم المزيد عن الأنواع المختلفة من المقارنات ، وكيف تجعلها JavaScript ، بما في ذلك الخصائص المهمة.
14+
=======
15+
In this article we'll learn more about different types of comparisons, how JavaScript makes them, including important peculiarities.
16+
17+
At the end you'll find a good recipe to avoid "javascript quirks"-related issues.
18+
>>>>>>> 445bda39806050acd96f87166a7c97533a0c67e9
1319
1420
## Boolean هي النتيجة
1521

@@ -197,13 +203,22 @@ alert( undefined == 0 ); // false (3)
197203
- المقارنات `(1)` و `(2)` إرجاع `false` لأنه يتم تحويل` undefined` إلى `NaN` و` NaN` هي قيمة رقمية خاصة تُرجع `false` لجميع المقارنات.
198204
- تحقق المساواة `((3)` تُرجع `false` لأن` undefined` تساوي فقط `null` و` undefined` ولا قيمة أخرى.
199205

206+
<<<<<<< HEAD
200207
### تجنب المشاكل
201208

202209
لماذا راجعنا هذه الأمثلة؟ هل يجب أن نتذكر هذه الخصائص المميزة طوال الوقت؟ حسنًا ، ليس حقًا. في الواقع ، ستصبح هذه الأشياء الصعبة مألوفة تدريجيًا بمرور الوقت ، ولكن هناك طريقة صلبة للتهرب من المشاكل معها:
203210

204211
فقط تعامل مع أي مقارنة بـ "undefined / null" باستثناء المساواة الصارمة `===` مع رعاية استثنائية.
205212

206213
لا تستخدم المقارنات `> => <<=` مع متغير قد يكون `فارغًا / غير محدد` ، ما لم تكن متأكدًا حقًا مما تفعله. إذا كان المتغير يمكن أن يكون له هذه القيم ، تحقق منها بشكل منفصل.
214+
=======
215+
### Avoid problems
216+
217+
Why did we go over these examples? Should we remember these peculiarities all the time? Well, not really. Actually, these tricky things will gradually become familiar over time, but there's a solid way to avoid problems with them:
218+
219+
- Treat any comparison with `undefined/null` except the strict equality `===` with exceptional care.
220+
- Don't use comparisons `>= > < <=` with a variable which may be `null/undefined`, unless you're really sure of what you're doing. If a variable can have these values, check for them separately.
221+
>>>>>>> 445bda39806050acd96f87166a7c97533a0c67e9
207222
208223
## ملخص
209224

1-js/05-data-types/02-number/article.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,12 +114,18 @@ alert( 123456..toString(36) ); // 2n9c
114114

115115
يختصر الجدول في الأسفل الاختلافات بين هذه التوابع:
116116

117+
<<<<<<< HEAD
117118
| | `Math.floor` | `Math.ceil` | `Math.round` | `Math.trunc` |
118119
| ---- | ---------- | --------- | ---------- | ---------- |
119120
| 3.1 | 3 | 4 | 3 | 3 |
120121
| 3.6 | 3 | 4 | 4 | 3 |
121122
| -1.1 | -2 | -1 | -1 | -1 |
122123
| -1.6 | -2 | -1 | -2 | -1 |
124+
=======
125+
For example, to round the number to the 2nd digit after the decimal, we can multiply the number by `100` (or a bigger power of 10), call the rounding function and then divide it back.
126+
```js run
127+
let num = 1.23456;
128+
>>>>>>> 445bda39806050acd96f87166a7c97533a0c67e9
123129
124130

125131

1-js/09-classes/01-class/article.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,11 @@ alert(user.name); // John
330330
alert(User.prototype.name); // undefined
331331
```
332332

333+
<<<<<<< HEAD
333334
من الناحية الفنية ، تتم معالجتها بعد أن يقوم المنشئ بعمله ، ويمكننا استخدامه بالنسبة لهم التعبيرات المعقدة واستدعاءات الوظائف:
335+
=======
336+
We can also assign values using more complex expressions and function calls:
337+
>>>>>>> 445bda39806050acd96f87166a7c97533a0c67e9
334338
335339
```js run
336340
class User {
@@ -343,9 +347,14 @@ let user = new User();
343347
alert(user.name); // John
344348
```
345349

350+
<<<<<<< HEAD
346351
### عمل طرق مرتبطة بحقول class
347352

348353
كما هو موضح في الفصل <info: bind> ، فإن وظائف JavaScript لها ديناميكية `this`. يعتمد ذلك على سياق المكالمة.
354+
=======
355+
356+
### Making bound methods with class fields
357+
>>>>>>> 445bda39806050acd96f87166a7c97533a0c67e9
349358
350359
لذلك إذا تم تمرير طريقة كائن واستدعاؤها في سياق آخر ، فلن يكون `هذا` مرجعاً إلى كائنه بعد الآن.
351360

@@ -374,6 +383,7 @@ setTimeout(button.click, 1000); // undefined
374383

375384
هناك طريقتان لإصلاحها ، كما هو موضح في الفصل <info: bind>:
376385

386+
<<<<<<< HEAD
377387
1. قم بتمرير دالة مجمعة ، مثل `setTimeout (() => button.click ()، 1000)`.
378388
2. ربط طريقة الاعتراض ، على سبيل المثال في المنشئ:
379389

@@ -399,6 +409,12 @@ setTimeout(button.click, 1000); // hello
399409
```
400410

401411
توفر حقول class بنية أكثر أناقة للحل الأخير:
412+
=======
413+
1. Pass a wrapper-function, such as `setTimeout(() => button.click(), 1000)`.
414+
2. Bind the method to object, e.g. in the constructor.
415+
416+
Class fields provide another, quite elegant syntax:
417+
>>>>>>> 445bda39806050acd96f87166a7c97533a0c67e9
402418
403419
```js run
404420
class Button {
@@ -417,9 +433,15 @@ let button = new Button("hello");
417433
setTimeout(button.click, 1000); // hello
418434
```
419435

436+
<<<<<<< HEAD
420437
ينشئ حقل الفئة `click = () => {...}` وظيفة مستقلة على كل كائن `Button` ، مع` this` مرتبطًا بالكائن. ثم يمكننا تمرير "button.click" في أي مكان ، وسيتم استدعاؤها باستخدام `this` الصحيح.
421438

422439
هذا مفيد بشكل خاص في بيئة المتصفح ، عندما نحتاج إلى إعداد طريقة كمستمع للأحداث.
440+
=======
441+
The class field `click = () => {...}` is created on a per-object basis, there's a separate function for each `Button` object, with `this` inside it referencing that object. We can pass `button.click` around anywhere, and the value of `this` will always be correct.
442+
443+
That's especially useful in browser environment, for event listeners.
444+
>>>>>>> 445bda39806050acd96f87166a7c97533a0c67e9
423445
424446
## ملخص
425447

1-js/09-classes/02-class-inheritance/article.md

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,13 @@ let rabbit = new Rabbit("White Rabbit", 10); // Error: this is not defined.
232232

233233
عفوًا! لدينا خطأ. الآن لا يمكننا إنشاء الأرانب. ماذا حصل؟
234234

235+
<<<<<<< HEAD
235236
الإجابة المختصرة هي: يجب على منشئو الفصول الموروثة استدعاء `super (...)` و (!) قبل ذلك باستخدام `this`.
237+
=======
238+
The short answer is:
239+
240+
- **Constructors in inheriting classes must call `super(...)`, and (!) do it before using `this`.**
241+
>>>>>>> 445bda39806050acd96f87166a7c97533a0c67e9
236242
237243
...لكن لماذا؟ ماذا يجري هنا؟ في الواقع ، يبدو الشرط غريبًا.
238244

@@ -245,7 +251,11 @@ let rabbit = new Rabbit("White Rabbit", 10); // Error: this is not defined.
245251
- عندما يتم تنفيذ وظيفة عادية باستخدام `new` ، فإنها تنشئ كائنًا فارغًا وتعينه بـ` this`.
246252
- ولكن عندما يعمل منشئ مشتق ، فإنه لا يفعل ذلك. وتتوقع من المُنشئ الأصلي أن يقوم بهذه المهمة.
247253

254+
<<<<<<< HEAD
248255
لذا يجب على المُنشئ المشتق استدعاء `super` من أجل تنفيذ مُنشئه الأصلي (غير المُشتق) ، وإلا فلن يتم إنشاء كائن` this`. وسنحصل على خطأ.
256+
=======
257+
So a derived constructor must call `super` in order to execute its parent (base) constructor, otherwise the object for `this` won't be created. And we'll get an error.
258+
>>>>>>> 445bda39806050acd96f87166a7c97533a0c67e9
249259
250260
لكي يعمل مُنشئ "الأرنب" ، يجب الاتصال بـ "super ()` قبل استخدام `this` ، كما يلي:
251261

@@ -281,7 +291,107 @@ alert(rabbit.earLength); // 10
281291
```
282292

283293

294+
<<<<<<< HEAD
284295
## Super: الأجزاء الداخلية ، [[HomeObject]]
296+
=======
297+
298+
### Overriding class fields: a tricky note
299+
300+
```warn header="Advanced note"
301+
This note assumes you have a certain experience with classes, maybe in other programming languages.
302+
303+
It provides better insight into the language and also explains the behavior that might be a source of bugs (but not very often).
304+
305+
If you find it difficult to understand, just go on, continue reading, then return to it some time later.
306+
```
307+
308+
We can override not only methods, but also class fields.
309+
310+
Although, there's a tricky behavior when we access an overridden field in parent constructor, quite different from most other programming languages.
311+
312+
Consider this example:
313+
314+
```js run
315+
class Animal {
316+
name = 'animal'
317+
318+
constructor() {
319+
alert(this.name); // (*)
320+
}
321+
}
322+
323+
class Rabbit extends Animal {
324+
name = 'rabbit';
325+
}
326+
327+
new Animal(); // animal
328+
*!*
329+
new Rabbit(); // animal
330+
*/!*
331+
```
332+
333+
Here, class `Rabbit` extends `Animal` and overrides `name` field with its own value.
334+
335+
There's no own constructor in `Rabbit`, so `Animal` constructor is called.
336+
337+
What's interesting is that in both cases: `new Animal()` and `new Rabbit()`, the `alert` in the line `(*)` shows `animal`.
338+
339+
**In other words, parent constructor always uses its own field value, not the overridden one.**
340+
341+
What's odd about it?
342+
343+
If it's not clear yet, please compare with methods.
344+
345+
Here's the same code, but instead of `this.name` field we call `this.showName()` method:
346+
347+
```js run
348+
class Animal {
349+
showName() { // instead of this.name = 'animal'
350+
alert('animal');
351+
}
352+
353+
constructor() {
354+
this.showName(); // instead of alert(this.name);
355+
}
356+
}
357+
358+
class Rabbit extends Animal {
359+
showName() {
360+
alert('rabbit');
361+
}
362+
}
363+
364+
new Animal(); // animal
365+
*!*
366+
new Rabbit(); // rabbit
367+
*/!*
368+
```
369+
370+
Please note: now the output is different.
371+
372+
And that's what we naturally expect. When the parent constructor is called in the derived class, it uses the overridden method.
373+
374+
...But for class fields it's not so. As said, the parent constructor always uses the parent field.
375+
376+
Why is there the difference?
377+
378+
Well, the reason is in the field initialization order. The class field is initialized:
379+
- Before constructor for the base class (that doesn't extend anything),
380+
- Imediately after `super()` for the derived class.
381+
382+
In our case, `Rabbit` is the derived class. There's no `constructor()` in it. As said previously, that's the same as if there was an empty constructor with only `super(...args)`.
383+
384+
So, `new Rabbit()` calls `super()`, thus executing the parent constructor, and (per the rule for derived classes) only after that its class fields are initialized. At the time of the parent constructor execution, there are no `Rabbit` class fields yet, that's why `Animal` fields are used.
385+
386+
This subtle difference between fields and methods is specific to JavaScript
387+
388+
Luckily, this behavior only reveals itself if an overridden field is used in the parent constructor. Then it may be difficult to understand what's going on, so we're explaining it here.
389+
390+
If it becomes a problem, one can fix it by using methods or getters/setters instead of fields.
391+
392+
393+
## Super: internals, [[HomeObject]]
394+
>>>>>>> 445bda39806050acd96f87166a7c97533a0c67e9
285395
286396
```warn header="معلومات متقدمة"
287397
إذا كنت تقرأ البرنامج التعليمي لأول مرة - فقد يتم تخطي هذا القسم.

1-js/13-modules/01-modules-intro/article.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,41 @@
11

22
# مقدّمة إلى الوِحدات
33

4+
<<<<<<< HEAD
45
سنرى سريعًا بينما تطبيقنا يكبُر حجمًا وتعقيدًا بأنّ علينا تقسيمه إلى ملفات متعدّدة، أو ”وِحدات“ (module). عادةً ما تحتوي الوِحدة على صنف أو مكتبة فيها دوالّ.
6+
=======
7+
As our application grows bigger, we want to split it into multiple files, so called "modules". A module may contain a class or a library of functions for a specific purpose.
8+
>>>>>>> 445bda39806050acd96f87166a7c97533a0c67e9
59
610
كانت محرّكات جافاسكربت تعمل لفترة طويلة جدًا دون أيّ صياغة وِحدات على مستوى اللغة، ولم تكن هذه بالمشكلة إذ أنّ السكربتات سابقًا كانت بسيطة وسهلة ولم يكن هناك داعٍ فعلي للوِحدات.
711

812
ولكن كالعادة صارت السكربتات هذه أكثر تعقيدًا وأكبر، فكان على المجتمع اختراع طرائق مختلفة لتنظيم الشيفرات في وحدات (أو مكتبات خاصّة تُحمّل تلك الوِحدات حين الطلب).
913

14+
<<<<<<< HEAD
1015
مثال:
16+
=======
17+
To name some (for historical reasons):
18+
>>>>>>> 445bda39806050acd96f87166a7c97533a0c67e9
1119
1220
- [AMD](https://en.wikipedia.org/wiki/Asynchronous_module_definition): هذه إحدى نُظم المكتبات القديمة جدًا والتي كتبت تنفيذها بدايةً المكتبة [require.js](http://requirejs.org/).
1321
- [CommonJS](http://wiki.commonjs.org/wiki/Modules/1.1): نظام الوِحدات الذي صُنِع لخوادم Node.js.
1422
- [UMD](https://github.com/umdjs/umd): نظام وِحدات آخر (اقتُرح ليكون للعموم أجمعين) وهو متوافق مع AMD وCommonJS.
1523

1624
أمّا الآن فهذه المكتبات صارت (أو تصير، يومًا بعد آخر) جزءًا من التاريخ، ولكن مع ذلك سنراها في السكربتات القديمة.
1725

26+
<<<<<<< HEAD
1827
ظهر نظام الوِحدات (على مستوى اللغة) في المعيار عام 2015، وتطوّر شيئًا فشيئًا منذئذ وصارت الآن أغلب المتصفّحات الرئيسة (كما و Node.js) تدعمه. لذا سيكون أفضل لو بدأنا دراسة عملها من الآن.
28+
=======
29+
The language-level module system appeared in the standard in 2015, gradually evolved since then, and is now supported by all major browsers and in Node.js. So we'll study the modern JavaScript modules from now on.
30+
>>>>>>> 445bda39806050acd96f87166a7c97533a0c67e9
1931
2032
## ما الوِحدة؟
2133

34+
<<<<<<< HEAD
2235
الوِحدة هي ملف، فقط. كلّ نص برمجي يساوي وحدة واحدة.
36+
=======
37+
A module is just a file. One script is one module. As simple as that.
38+
>>>>>>> 445bda39806050acd96f87166a7c97533a0c67e9
2339
2440
يمكن أن تُحمّل الوِحدات بعضها البعض وتستعمل توجيهات خاصة مثل التصدير `export` والاستيراد `import` لتتبادل الميزات فيما بينها وتستدعي الدوالّ الموجودة في وحدة ص، من وحدة س:
2541

@@ -55,7 +71,15 @@ sayHi('John'); // Hello, John!
5571

5672
[codetabs src="say" height="140" current="index.html"]
5773

74+
<<<<<<< HEAD
5875
يجلب المتصفّح الوِحدة تلقائيًا ويقيم الشيفرة البرمجية بداخلها (ويستورد جميع الوحدات المتعلقة بها إن لزم الأمر)، وثمّ يشغلها.
76+
=======
77+
The browser automatically fetches and evaluates the imported module (and its imports if needed), and then runs the script.
78+
79+
```warn header="Modules work only via HTTP(s), not in local files"
80+
If you try to open a web-page locally, via `file://` protocol, you'll find that `import/export` directives don't work. Use a local web-server, such as [static-server](https://www.npmjs.com/package/static-server#getting-started) or use the "live server" capability of your editor, such as VS Code [Live Server Extension](https://marketplace.visualstudio.com/items?itemName=ritwickdey.LiveServer) to test modules.
81+
```
82+
>>>>>>> 445bda39806050acd96f87166a7c97533a0c67e9
5983
6084

6185
## ميزات الوِحدات الأساسية

2-ui/1-document/01-browser-environment/article.md

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
The JavaScript language was initially created for web browsers. Since then it has evolved and become a language with many uses and platforms.
44

5-
A platform may be a browser, or a web-server or another *host*, even a coffee machine. Each of them provides platform-specific functionality. The JavaScript specification calls that a *host environment*.
5+
A platform may be a browser, or a web-server or another *host*, even a "smart" coffee machine, if it can run JavaScript. Each of them provides platform-specific functionality. The JavaScript specification calls that a *host environment*.
66

77
A host environment provides own objects and functions additional to the language core. Web browsers give a means to control web pages. Node.js provides server-side features, and so on.
88

9-
Here's a bird's-eye view of what we have when JavaScript runs in a web-browser:
9+
Here's a bird's-eye view of what we have when JavaScript runs in a web browser:
1010

1111
![](windowObjects.svg)
1212

@@ -49,9 +49,7 @@ document.body.style.background = "red";
4949
setTimeout(() => document.body.style.background = "", 1000);
5050
```
5151

52-
Here we used `document.body.style`, but there's much, much more. Properties and methods are described in the specification:
53-
54-
- **DOM Living Standard** at <https://dom.spec.whatwg.org>
52+
Here we used `document.body.style`, but there's much, much more. Properties and methods are described in the specification: [DOM Living Standard](https://dom.spec.whatwg.org).
5553

5654
```smart header="DOM is not only for browsers"
5755
The DOM specification explains the structure of a document and provides objects to manipulate it. There are non-browser instruments that use DOM too.
@@ -60,9 +58,9 @@ For instance, server-side scripts that download HTML pages and process them can
6058
```
6159

6260
```smart header="CSSOM for styling"
63-
CSS rules and stylesheets are structured in a different way than HTML. There's a separate specification, [CSS Object Model (CSSOM)](https://www.w3.org/TR/cssom-1/), that explains how they are represented as objects, and how to read and write them.
61+
There's also a separate specification, [CSS Object Model (CSSOM)](https://www.w3.org/TR/cssom-1/) for CSS rules and stylesheets, that explains how they are represented as objects, and how to read and write them.
6462
65-
CSSOM is used together with DOM when we modify style rules for the document. In practice though, CSSOM is rarely required, because usually CSS rules are static. We rarely need to add/remove CSS rules from JavaScript, but that's also possible.
63+
CSSOM is used together with DOM when we modify style rules for the document. In practice though, CSSOM is rarely required, because we rarely need to modify CSS rules from JavaScript (usually we just add/remove CSS classes, not modify their CSS rules), but that's also possible.
6664
```
6765

6866
## BOM (Browser Object Model)

0 commit comments

Comments
 (0)