You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: 1-js/04-object-basics/08-symbol/article.md
+45-45
Original file line number
Diff line number
Diff line change
@@ -1,31 +1,31 @@
1
1
2
-
# Symbol type
2
+
# সিম্বল টাইপ
3
3
4
-
By specification, object property keys may be either of string type, or of symbol type. Not numbers, not booleans, only strings or symbols, these two types.
4
+
অবজেক্টের স্পেসিফিকেশন অনুযায়ী আমরা জেনেছি প্রপার্টি কি(key) হতে পারে স্ট্রিং অথবা সিম্বল টাইপ। নাম্বার, বুলিয়ান বা অন্য কোন ধরণের প্রিমিটিভ টাইপ কি(key) হিসেবে রাখা যায় না, শুধুমাত্র স্ট্রিং অথবা সিম্বল এই দুটি টাইপ অ্যাক্সেপ্টবেল।
5
5
6
-
Till now we've been using only strings. Now let's see the benefits that symbols can give us.
6
+
পূর্বের অনুচ্ছেদগুলোতে আমরা প্রপার্টি হিসেবে শুধুমাত্র স্ট্রিং ব্যবহার করেছি, এই অনুচ্ছেদে আমরা সিম্বল টাইপ কিভাবে ব্যবহার করা যায় এবং এর ব্যবহারের সুবিধা কি তা নিয়ে আলোচনা করব।
7
7
8
-
## Symbols
8
+
## সিম্বল
9
9
10
-
A "symbol" represents a unique identifier.
10
+
"সিম্বল (symbol)" একটি একক বৈশিষ্ট্য প্রদানের নিশ্চয়তা প্রদান করে।
11
11
12
-
A value of this type can be created using`Symbol()`:
12
+
এই ধরণের টাইপ তৈরি করতে আমরা ব্যবহার করি`Symbol()`:
13
13
14
14
```js
15
-
// id is a new symbol
15
+
//এখানে id হল একটি symbol
16
16
let id =Symbol();
17
17
```
18
18
19
-
Upon creation, we can give symbol a description (also called a symbol name), mostly useful for debugging purposes:
19
+
তৈরির সময়, আমরা সিম্বলের একটি নাম প্রদান করি, যা ডিবাগিংয়ের জন্য সুবিধাজনক:
20
20
21
21
```js
22
-
// id is a symbol with the description "id"
22
+
//এখানে id হল একটি Symbol যার নাম হল "id"
23
23
let id =Symbol("id");
24
24
```
25
25
26
-
Symbols are guaranteed to be unique. Even if we create many symbols with the same description, they are different values. The description is just a label that doesn't affect anything.
26
+
Symbol আমাদের নিশ্চয়তা প্রদান করে এর মান হবে অদ্বিতীয়। যদি আমরা একই নাম দ্বারা একাধিক সিম্বল তৈরি করি, তাদের মান হবে আলাদা। সিম্বলের প্রদানকৃত নামটি শুধুমাত্র একটি লেভেল।
27
27
28
-
For instance, here are two symbols with the same description -- they are not equal:
28
+
যেমন, এখানে আমরা এখানে একই নামের দুটি সিম্বল তৈরি করেছি -- কন্ডিশনালি এদের মান সমান হবে না:
29
29
30
30
```js run
31
31
let id1 =Symbol("id");
@@ -36,12 +36,12 @@ alert(id1 == id2); // false
36
36
*/!*
37
37
```
38
38
39
-
If you are familiar with Ruby or another language that also has some sort of "symbols" -- please don't be misguided. JavaScript symbols are different.
39
+
রুবি বা অন্য যেকোন ল্যাংগুয়েজের "symbols" এর সাথে এটিকে গুলিয়ে ফেলবেন না। জাভাস্ক্রিপ্টের সিম্বল আলাদা।
40
40
41
-
````warn header="Symbols don't auto-convert to a string"
42
-
Most values in JavaScript support implicit conversion to a string. For instance, we can `alert` almost any value, and it will work. Symbols are special. They don't auto-convert.
41
+
````warn header="Symbols স্বয়ংক্রিয়ভাবে স্ট্রিং এ কনভার্ট হয়না"
42
+
জাভস্ক্রিপ্টের বেশিরভাগ মান স্ট্রিংয়ে টাইপ কাস্টিং হতে পারে। যেমন `alert` প্রায় সবধরণের মানকে স্ট্রিংয়ে রূপান্তর করতে পারে। তবে সিম্বল অটো কনভার্ট হতে পারে না।
43
43
44
-
For instance, this `alert` will show an error:
44
+
যেমন, নিচের কোডটিতে `alert` এর জন্য এরর দেখাবে:
45
45
46
46
```js run
47
47
let id = Symbol("id");
@@ -50,17 +50,17 @@ alert(id); // TypeError: Cannot convert a Symbol value to a string
50
50
*/!*
51
51
```
52
52
53
-
That's a "language guard" against messing up, because strings and symbols are fundamentally different and should not accidentally convert one into another.
53
+
That's a "language guard" against messing up, কেননা স্ট্রিং এবং সিম্বল মৌলিকভাবে আলাদা যার জন্য এদের নিজেদের মধ্যে পরিবর্তন গ্রহণযোগ্য নয়।
54
54
55
-
If we really want to show a symbol, we need to explicitly call `.toString()` on it, like here:
55
+
যদি আমরা কোন একটি সিম্বল দেখাতে চাই, তাহলে `.toString()` মেথডের মাধ্যমে দেখাতে পারি, এভাবে:
56
56
```js run
57
57
let id = Symbol("id");
58
58
*!*
59
-
alert(id.toString()); // Symbol(id), now it works
59
+
alert(id.toString()); // Symbol(id), এখন এটি কাজ করবে
60
60
*/!*
61
61
```
62
62
63
-
Or get `symbol.description` property to show the description only:
63
+
অথবা নাম জানতে `symbol.description`:
64
64
```js run
65
65
let id = Symbol("id");
66
66
*!*
@@ -70,33 +70,33 @@ alert(id.description); // id
70
70
71
71
````
72
72
73
-
## "Hidden" properties
73
+
## "হিডেন" প্রপার্টি
74
74
75
-
Symbols allow us to create "hidden" properties of an object, that no other part of code can accidentally access or overwrite.
75
+
সিম্বল অবজেক্টের মধ্যে একটি "hidden" প্রপার্টি রাখার সুবিধা প্রদান করে, যাতে অনিচ্ছাকৃত কোন প্রপার্টি অ্যাক্সেস বা ওভাররাইট করা না যায়।
76
76
77
-
For instance, if we're working with `user`objects, that belong to a third-party code. We'd like to add identifiers to them.
77
+
যেমন, আমাদের একটি `user`অবজেক্ট আছে, যেটি অন্য আরেকটি থার্ড-পার্টি কোডের সাথে সম্পর্কিত। এখন আমরা এর জন্য একটি আইডেন্টিফায়ার সেট করতে চাই।
78
78
79
-
Let's use a symbol key for it:
79
+
চলুন এর জন্য একটি সিম্বল প্রপার্টি ব্যবহার করি:
80
80
81
81
```js run
82
-
let user = { //belongs to another code
82
+
let user = { //যা অন্য আরেকটি কোডের সাথে সম্পর্কিত
83
83
name:"John"
84
84
};
85
85
86
86
let id =Symbol("id");
87
87
88
88
user[id] =1;
89
89
90
-
alert( user[id] ); //we can access the data using the symbol as the key
90
+
alert( user[id] ); //এখন আমরা এর ডাটাকে সিম্বল কী(Key) দ্বারা অ্যাক্সেস করতে পারব
91
91
```
92
92
93
-
What's the benefit of using `Symbol("id")` over a string `"id"`?
93
+
এটিতো আমরা চাইলে স্ট্রিং প্রপার্টি `"id"` দ্বারা করতে পারতাম তার পরিবর্তে `Symbol("id")` ব্যবহার সুবিধাজনক কেন?
94
94
95
-
As`user`objects belongs to another code, and that code also works with them, we shouldn't just add any fields to it. That's unsafe. But a symbol cannot be accessed accidentally, the third-party code probably won't even see it, so it's probably all right to do.
95
+
যেহেতু`user`অবজেক্টটি অন্য আরেকটি স্ক্রিপ্টের সাথেও সম্পর্কিত, এবং ঐ কোডটিও যেহেতু `user` অবজেক্ট নিয়ে কাজ করে, আমরা চাইনা এর মধ্যে নতুন আরেকটি ফিল্ড যুক্ত হোক। এবং নিরাপত্তার জন্য এটি থার্ড পার্টির জন্য অ্যাক্সেসবল হওয়াও উচিত নয়, সিম্বল ব্যবহার করায় আমরা এই ব্যাপারে নিশ্চিত থাকতে পারি সিম্বল ডাটাসমূহ এক স্ক্রিপ্টের সাথে অন্য স্ক্রিপ্টের মধ্যে আদান প্রদান হবে না।
96
96
97
97
Also, imagine that another script wants to have its own identifier inside `user`, for its own purposes. That may be another JavaScript library, so that the scripts are completely unaware of each other.
98
98
99
-
Then that script can create its own `Symbol("id")`, like this:
99
+
এক্ষেত্রে ঐ স্ক্রিপ্ট নিজস্ব সিম্বল তৈরি করতে পারে এভাবে, `Symbol("id")`:
100
100
101
101
```js
102
102
// ...
@@ -105,28 +105,28 @@ let id = Symbol("id");
105
105
user[id] ="Their id value";
106
106
```
107
107
108
-
There will be no conflict between our and their identifiers, because symbols are always different, even if they have the same name.
108
+
এক্ষেত্রে দুটি স্ক্রিপ্টের মধ্যে কোন কনফ্লিক্ট হবে না, কেননা সিম্বলের নাম এক হলেও সিম্বলসমূহ হবে ইউনিক,
109
109
110
-
...But if we used a string `"id"`instead of a symbol for the same purpose, then there *would* be a conflict:
110
+
...যদি তার পরিবর্তে আমরা প্রপার্টি হিসেবে স্ট্রিং`"id"`ব্যবহার করি, তাহলে উভয়ের মাঝে কনফ্লিক্ট হবে:
111
111
112
112
```js run
113
113
let user = { name:"John" };
114
114
115
-
//Our script uses "id" property
115
+
//আমাদের user এর "id" প্রপার্টি
116
116
user.id="Our id value";
117
117
118
-
// ...Another script also wants "id" for its purposes...
118
+
// ...অন্য আরেকটি স্ক্রিপ্টও কোন কারণে "id" প্রপার্টি ব্যবহার করছে
119
119
120
120
user.id="Their id value"
121
-
//Boom! overwritten by another script!
121
+
//ওহহহ! আরেকটি স্ক্রিপ্ট দ্বারা ওভাররাইড হয়ে গেল :(
122
122
```
123
123
124
-
### Symbols in an object literal
124
+
### অবজেক্ট লিটারেল এ `{...}` সিম্বল প্রপার্টি
125
125
126
126
127
-
If we want to use a symbol in an object literal `{...}`, we need square brackets around it.
127
+
যদি আমরা অবজেক্ট লিটারেলে `{...}` সিম্বল প্রপার্টি ব্যবহার করতে চাই, এর জন্য আমরা এটি তৃতীয় বন্ধনীর মধ্যে লিখতে হবে।
128
128
129
-
Like this:
129
+
যেমন:
130
130
131
131
```js
132
132
let id =Symbol("id");
@@ -138,13 +138,13 @@ let user = {
138
138
*/!*
139
139
};
140
140
```
141
-
That's because we need the value from the variable `id`as the key, not the string "id".
141
+
কেননা এটি দ্বারা আমরা নিশ্চিত করতে পারি, এখানের `id`হল একটি সিম্বল টাইপের ভ্যারিয়েবল, প্রপার্টির নাম স্ট্রিং "id" না।
142
142
143
-
### Symbols are skipped by for..in
143
+
### for..in লুপের মধ্যে সিম্বল প্রপার্টি অ্যাক্সেসবল না
144
144
145
-
Symbolic properties do not participate in `for..in`loop.
145
+
সিম্বল প্রপার্টি সমূহ `for..in`লুপের মধ্যে অ্যাক্সেসবল না।
146
146
147
-
For instance:
147
+
যেমন:
148
148
149
149
```js run
150
150
let id =Symbol("id");
@@ -155,16 +155,16 @@ let user = {
155
155
};
156
156
157
157
*!*
158
-
for (let key in user) alert(key); // name, age (no symbols)
158
+
for (let key in user) alert(key); // name, age (সিম্বল প্রপার্টি দেখাবে না)
159
159
*/!*
160
160
161
-
//the direct access by the symbol works
161
+
//তবে সরাসরি এটি অ্যাক্সেসবল
162
162
alert( "Direct: "+ user[id] );
163
163
```
164
164
165
-
`Object.keys(user)`also ignores them. That's a part of the general "hiding symbolic properties" principle. If another script or a library loops over our object, it won't unexpectedly access a symbolic property.
165
+
`Object.keys(user)`এর জন্যও সিম্বল প্রপার্টি অ্যাক্সেসবল না। কেননা এটি "হাইড সিম্বল প্রপার্টির" নিয়ম মেনে চলে। অন্যথায় অন্য আরেকটি স্ক্রিপ্ট হতে আমাদের অবজেক্টের মধ্যে লুপ চালিয়ে আমরা সিম্বল প্রপার্টির মান জেনে যেতে পারি, যা উচিত নয়।
166
166
167
-
In contrast, [Object.assign](mdn:js/Object/assign)copies both string and symbol properties:
167
+
তবে, [Object.assign](mdn:js/Object/assign)এর ক্ষেত্রে উভয় টাইপের প্রপার্টি কপি হয়, যেমন:
168
168
169
169
```js run
170
170
let id =Symbol("id");
@@ -177,7 +177,7 @@ let clone = Object.assign({}, user);
177
177
alert( clone[id] ); // 123
178
178
```
179
179
180
-
There's no paradox here. That's by design. The idea is that when we clone an object or merge objects, we usually want *all* properties to be copied (including symbols like `id`).
180
+
তবে এ নিয়ে চিন্তিত হওয়া উচিত নই। কেননা এদের এমনভাবে ডিজাইন করা হয়েছে যেন আমরা কোন অবজেক্টকে ক্লোন বা মার্জ করতে পারি। সাধারণত এজন্য আমরা চাই সকল ধরণের প্রপার্টি(সিম্বল সহ) কপি হোক।
0 commit comments