Skip to content

Commit 67d1152

Browse files
committed
Translating global Object to Ar
1 parent dd28bc7 commit 67d1152

1 file changed

Lines changed: 40 additions & 33 deletions

File tree

  • 1-js/06-advanced-functions/05-global-object
Lines changed: 40 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,87 +1,94 @@
11

2-
# Global object
2+
# الكائن العمومي Global object
33

4-
The global object provides variables and functions that are available anywhere. By default, those that are built into the language or the environment.
4+
تقدّم الكائنات العمومية متغيراتَ ودوال يمكن استعمالها من أي مكان. هذه الكائنات مضمّنة في بنية اللغة أو البيئة مبدئيًا.
55

6-
In a browser it is named `window`, for Node.js it is `global`, for other environments it may have another name.
6+
في المتصفّحات تُدعى بالنافذة `window` وفي Node.js تُدعى بالعموميات `global` وفي باقي البيئات تُدعى بأيّ اسم مناسب يراه مطوّروها.
77

8-
Recently, `globalThis` was added to the language, as a standardized name for a global object, that should be supported across all environments. In some browsers, namely non-Chromium Edge, `globalThis` is not yet supported, but can be easily polyfilled.
8+
أُضيف حديثًا الكائن `globalThis` إلى اللغة ليكون اسم قياسيًا للكائن العمومي على أن تدعمه كلّ البيئات. ولكن بعض المتصفّحات (وبالخصوص عدا Chromium Edge) لا تدعم هذا الكائن بعد، ولكن يمكنك «ترقيعه تعدّديًا» بسهولة تامة.
99

10-
We'll use `window` here, assuming that our environment is a browser. If your script may run in other environments, it's better to use `globalThis` instead.
10+
سنستعمل هنا `window` على فرضية بأنّ البيئة هي المتصفّح نفسه. لو كنت ستشغّل السكربت الذي تكتبه في بيئات أخرى فربما تستعمل `globalThis` بدل النافذة تلك.
1111

12-
All properties of the global object can be accessed directly:
12+
يمكننا طبعًا الوصول إلى كافة خصائص الكائن العمومي مباشرةً:
1313

1414
```js run
1515
alert("Hello");
16-
// is the same as
16+
// تتطابق تمامًا مع
1717
window.alert("Hello");
18+
1819
```
1920

20-
In a browser, global functions and variables declared with `var` (not `let/const`!) become the property of the global object:
21+
يمكنك في المتصفّحات التصريح عن الدوال العمومية والمتغيرات باستعمال `var` (وليس `let/const` !) لتصير خاصيات للكائن العمومي:
2122

2223
```js run untrusted refresh
2324
var gVar = 5;
2425

25-
alert(window.gVar); // 5 (became a property of the global object)
26+
alert(window.gVar); // ‫5 (تصير خاصية من خاصيات الكائن العمومي)
27+
2628
```
2729

28-
Please don't rely on that! This behavior exists for compatibility reasons. Modern scripts use [JavaScript modules](info:modules) where such thing doesn't happen.
30+
ولكن أرجوك ألا تعتمد على هذا الأمر! هذا السلوك موجود للتوافقية لا غير. تستعمل السكربتات الحديثة [وحداتَ جافاسكربت](info:modules) حيث لا يحدث هكذا أمر.
2931

30-
If we used `let` instead, such thing wouldn't happen:
32+
لن يحدث هذا لو استعملنا `let` هنا:
3133

3234
```js run untrusted refresh
3335
let gLet = 5;
3436

35-
alert(window.gLet); // undefined (doesn't become a property of the global object)
37+
alert(window.gLet); // ‫غير معرّف (لا تصير خاصية للكائن العمومي)
38+
3639
```
3740

38-
If a value is so important that you'd like to make it available globally, write it directly as a property:
41+
لو كانت القيمة هامّة جدًا جدًا وأردت أن تدخل عليها من أيّ مكان عمومي فاكتبها على أنّها خاصية مباشرةً:
3942

4043
```js run
41-
*!*
42-
// make current user information global, to let all scripts access it
44+
// نجعل من معلومات المستخدم الحالي عمومية لتصل إليها كلّ السكربتات
4345
window.currentUser = {
4446
name: "John"
4547
};
46-
*/!*
4748

48-
// somewhere else in code
49+
// وفي مكان آخر يريدها أحد
4950
alert(currentUser.name); // John
5051

51-
// or, if we have a local variable with the name "currentUser"
52-
// get it from window explicitly (safe!)
52+
// ‫أو (لو كان هناك المتغير المحلي ذا الاسم «currentUser»
53+
// فنأخذها جهارةً من النافذة (وهذا آمن!)
5354
alert(window.currentUser.name); // John
55+
5456
```
5557

56-
That said, using global variables is generally discouraged. There should be as few global variables as possible. The code design where a function gets "input" variables and produces certain "outcome" is clearer, less prone to errors and easier to test than if it uses outer or global variables.
58+
نختم هنا بأنّ استعمال المتغيرات العمومية غير محبّذ بالمرة ويجب أن يكون عددها بأقل ما يمكن. يُعدّ مبدأ تصميم الشيفرات حين تأخذ الدالة المتغيرات «الداخلة» وتُعطينا «نواتج» معيّنة - يُعدّ هذا المبدأ أفضل وأقلّ عُرضة للأخطاء وأسهل للاختبار موازنةً بالمتغيرات الخارجية أو العمومية.
5759

58-
## Using for polyfills
5960

60-
We use the global object to test for support of modern language features.
61+
## استعمالها للترقيع تعدديًا
62+
63+
المجال الذي نستعمل الكائنات العمومية فيه هو اختبار لو كانت البيئة تدعم مزايا اللغة الحديثة.
64+
65+
فمثلًا يمكننا اختبار لو كانت كائنات الوعود `‎Promise‎` المضمّنة في اللغة مضمّنة حقًا (لم تكن كذلك في المتصفحات العتيقة):
6166

62-
For instance, test if a built-in `Promise` object exists (it doesn't in really old browsers):
6367
```js run
6468
if (!window.Promise) {
65-
alert("Your browser is really old!");
69+
alert("Your browser is really old!"); // ‫تستعمل متصفّحا قديماً!
6670
}
6771
```
6872

69-
If there's none (say, we're in an old browser), we can create "polyfills": add functions that are not supported by the environment, but exist in the modern standard.
73+
لو لم نجد هذه الكائنات (مثلًا نستعمل متصفّحًا قديمًا) فيمكننا «ترقيعه تعدّديًا»: أي إضافة الدوال التي لا تدعمها البيئة بينما هي موجودة في معيار اللغة الحديث.
7074

7175
```js run
7276
if (!window.Promise) {
73-
window.Promise = ... // custom implementation of the modern language feature
77+
window.Promise = ... // شيفرة نكتبها بنفسنا تؤدّي الميزة الحديثة في اللغة هذه
7478
}
79+
7580
```
7681

77-
## Summary
82+
## ملخص
7883

7984
- The global object holds variables that should be available everywhere.
8085

81-
That includes JavaScript built-ins, such as `Array` and environment-specific values, such as `window.innerHeight` -- the window height in the browser.
82-
- The global object has a universal name `globalThis`.
86+
تشمل المتغيرات هذه كل ما هو مضمّن في بنية لغة جافاسكربت مثل
87+
المصفوفات `‎Array‎` والقيم المخصّصة للبيئة مثل `‎window.innerHeight‎` (ارتفاع نافذة المتصفّح).
88+
- للكائن العمومي اسم عام في المواصفة: `‎globalThis‎`.
8389

84-
...But more often is referred by "old-school" environment-specific names, such as `window` (browser) and `global` (Node.js). As `globalThis` is a recent proposal, it's not supported in non-Chromium Edge (but can be polyfilled).
85-
- We should store values in the global object only if they're truly global for our project. And keep their number at minimum.
86-
- In-browser, unless we're using [modules](info:modules), global functions and variables declared with `var` become a property of the global object.
87-
- To make our code future-proof and easier to understand, we should access properties of the global object directly, as `window.x`.
90+
ولكن... دومًا ما نُشير إليه بالأسماء «الأثرية» حسب كل بيئة مثل `‎window‎` (في المتصفحات) و`‎global‎` (في Node.js)
91+
، إذ أنّ `‎globalThis‎` هو مُقترح جديد على اللغة وليس مدعومًا في المتصفّحات عدة Chromium Edge (ولكن يمكننا ترقيعه تعدّديًا).
92+
- علينا ألا نخزّن القيم في الكائن العمومي إلّا لو كانت حقًا وفعلًا عمومية للمشروع الذي نعمل عليه. كما ويجب أن يبقى عددها بأقل ما يمكن.
93+
- حين نطوّر لاستعمال الشيفرات في المتصفّحات (لو لم نستعمل الوحدات، [وحدات](info:modules))، تصير الدوال العمومية والمتغيرات باستعمال `‎var‎` خاصيات للكائن العمومي.
94+
- علينا استعمال خاصيات الكائن العمومي مباشرةً (مثل `‎window.x‎`) لتكون الشيفرة سهلة الصيانة مستقبلًا وأسهل فهمًا.

0 commit comments

Comments
 (0)