Skip to content

Commit 90da453

Browse files
committed
wip symbol
1 parent 76df5fd commit 90da453

File tree

1 file changed

+45
-45
lines changed

1 file changed

+45
-45
lines changed

Diff for: 1-js/04-object-basics/08-symbol/article.md

+45-45
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,31 @@
11

2-
# Symbol type
2+
# সিম্বল টাইপ
33

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) হিসেবে রাখা যায় না, শুধুমাত্র স্ট্রিং অথবা সিম্বল এই দুটি টাইপ অ্যাক্সেপ্টবেল।
55

6-
Till now we've been using only strings. Now let's see the benefits that symbols can give us.
6+
পূর্বের অনুচ্ছেদগুলোতে আমরা প্রপার্টি হিসেবে শুধুমাত্র স্ট্রিং ব্যবহার করেছি, এই অনুচ্ছেদে আমরা সিম্বল টাইপ কিভাবে ব্যবহার করা যায় এবং এর ব্যবহারের সুবিধা কি তা নিয়ে আলোচনা করব।
77

8-
## Symbols
8+
## সিম্বল
99

10-
A "symbol" represents a unique identifier.
10+
"সিম্বল (symbol)" একটি একক বৈশিষ্ট্য প্রদানের নিশ্চয়তা প্রদান করে।
1111

12-
A value of this type can be created using `Symbol()`:
12+
এই ধরণের টাইপ তৈরি করতে আমরা ব্যবহার করি `Symbol()`:
1313

1414
```js
15-
// id is a new symbol
15+
// এখানে id হল একটি symbol
1616
let id = Symbol();
1717
```
1818

19-
Upon creation, we can give symbol a description (also called a symbol name), mostly useful for debugging purposes:
19+
তৈরির সময়, আমরা সিম্বলের একটি নাম প্রদান করি, যা ডিবাগিংয়ের জন্য সুবিধাজনক:
2020

2121
```js
22-
// id is a symbol with the description "id"
22+
// এখানে id হল একটি Symbol যার নাম হল "id"
2323
let id = Symbol("id");
2424
```
2525

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 আমাদের নিশ্চয়তা প্রদান করে এর মান হবে অদ্বিতীয়। যদি আমরা একই নাম দ্বারা একাধিক সিম্বল তৈরি করি, তাদের মান হবে আলাদা। সিম্বলের প্রদানকৃত নামটি শুধুমাত্র একটি লেভেল।
2727

28-
For instance, here are two symbols with the same description -- they are not equal:
28+
যেমন, এখানে আমরা এখানে একই নামের দুটি সিম্বল তৈরি করেছি -- কন্ডিশনালি এদের মান সমান হবে না:
2929

3030
```js run
3131
let id1 = Symbol("id");
@@ -36,12 +36,12 @@ alert(id1 == id2); // false
3636
*/!*
3737
```
3838

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" এর সাথে এটিকে গুলিয়ে ফেলবেন না। জাভাস্ক্রিপ্টের সিম্বল আলাদা।
4040

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` প্রায় সবধরণের মানকে স্ট্রিংয়ে রূপান্তর করতে পারে। তবে সিম্বল অটো কনভার্ট হতে পারে না।
4343
44-
For instance, this `alert` will show an error:
44+
যেমন, নিচের কোডটিতে `alert` এর জন্য এরর দেখাবে:
4545
4646
```js run
4747
let id = Symbol("id");
@@ -50,17 +50,17 @@ alert(id); // TypeError: Cannot convert a Symbol value to a string
5050
*/!*
5151
```
5252
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, কেননা স্ট্রিং এবং সিম্বল মৌলিকভাবে আলাদা যার জন্য এদের নিজেদের মধ্যে পরিবর্তন গ্রহণযোগ্য নয়।
5454
55-
If we really want to show a symbol, we need to explicitly call `.toString()` on it, like here:
55+
যদি আমরা কোন একটি সিম্বল দেখাতে চাই, তাহলে `.toString()` মেথডের মাধ্যমে দেখাতে পারি, এভাবে:
5656
```js run
5757
let id = Symbol("id");
5858
*!*
59-
alert(id.toString()); // Symbol(id), now it works
59+
alert(id.toString()); // Symbol(id), এখন এটি কাজ করবে
6060
*/!*
6161
```
6262
63-
Or get `symbol.description` property to show the description only:
63+
অথবা নাম জানতে `symbol.description`:
6464
```js run
6565
let id = Symbol("id");
6666
*!*
@@ -70,33 +70,33 @@ alert(id.description); // id
7070
7171
````
7272

73-
## "Hidden" properties
73+
## "হিডেন" প্রপার্টি
7474

75-
Symbols allow us to create "hidden" properties of an object, that no other part of code can accidentally access or overwrite.
75+
সিম্বল অবজেক্টের মধ্যে একটি "hidden" প্রপার্টি রাখার সুবিধা প্রদান করে, যাতে অনিচ্ছাকৃত কোন প্রপার্টি অ্যাক্সেস বা ওভাররাইট করা না যায়।
7676

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` অবজেক্ট আছে, যেটি অন্য আরেকটি থার্ড-পার্টি কোডের সাথে সম্পর্কিত। এখন আমরা এর জন্য একটি আইডেন্টিফায়ার সেট করতে চাই।
7878

79-
Let's use a symbol key for it:
79+
চলুন এর জন্য একটি সিম্বল প্রপার্টি ব্যবহার করি:
8080

8181
```js run
82-
let user = { // belongs to another code
82+
let user = { // যা অন্য আরেকটি কোডের সাথে সম্পর্কিত
8383
name: "John"
8484
};
8585

8686
let id = Symbol("id");
8787

8888
user[id] = 1;
8989

90-
alert( user[id] ); // we can access the data using the symbol as the key
90+
alert( user[id] ); // এখন আমরা এর ডাটাকে সিম্বল কী(Key) দ্বারা অ্যাক্সেস করতে পারব
9191
```
9292

93-
What's the benefit of using `Symbol("id")` over a string `"id"`?
93+
এটিতো আমরা চাইলে স্ট্রিং প্রপার্টি `"id"` দ্বারা করতে পারতাম তার পরিবর্তে `Symbol("id")` ব্যবহার সুবিধাজনক কেন?
9494

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` অবজেক্ট নিয়ে কাজ করে, আমরা চাইনা এর মধ্যে নতুন আরেকটি ফিল্ড যুক্ত হোক। এবং নিরাপত্তার জন্য এটি থার্ড পার্টির জন্য অ্যাক্সেসবল হওয়াও উচিত নয়, সিম্বল ব্যবহার করায় আমরা এই ব্যাপারে নিশ্চিত থাকতে পারি সিম্বল ডাটাসমূহ এক স্ক্রিপ্টের সাথে অন্য স্ক্রিপ্টের মধ্যে আদান প্রদান হবে না।
9696

9797
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.
9898

99-
Then that script can create its own `Symbol("id")`, like this:
99+
এক্ষেত্রে ঐ স্ক্রিপ্ট নিজস্ব সিম্বল তৈরি করতে পারে এভাবে, `Symbol("id")`:
100100

101101
```js
102102
// ...
@@ -105,28 +105,28 @@ let id = Symbol("id");
105105
user[id] = "Their id value";
106106
```
107107

108-
There will be no conflict between our and their identifiers, because symbols are always different, even if they have the same name.
108+
এক্ষেত্রে দুটি স্ক্রিপ্টের মধ্যে কোন কনফ্লিক্ট হবে না, কেননা সিম্বলের নাম এক হলেও সিম্বলসমূহ হবে ইউনিক,
109109

110-
...But if we used a string `"id"` instead of a symbol for the same purpose, then there *would* be a conflict:
110+
...যদি তার পরিবর্তে আমরা প্রপার্টি হিসেবে স্ট্রিং`"id"` ব্যবহার করি, তাহলে উভয়ের মাঝে কনফ্লিক্ট হবে:
111111

112112
```js run
113113
let user = { name: "John" };
114114

115-
// Our script uses "id" property
115+
// আমাদের user এর "id" প্রপার্টি
116116
user.id = "Our id value";
117117

118-
// ...Another script also wants "id" for its purposes...
118+
// ...অন্য আরেকটি স্ক্রিপ্টও কোন কারণে "id" প্রপার্টি ব্যবহার করছে
119119

120120
user.id = "Their id value"
121-
// Boom! overwritten by another script!
121+
// ওহহহ! আরেকটি স্ক্রিপ্ট দ্বারা ওভাররাইড হয়ে গেল :(
122122
```
123123

124-
### Symbols in an object literal
124+
### অবজেক্ট লিটারেল এ `{...}` সিম্বল প্রপার্টি
125125

126126

127-
If we want to use a symbol in an object literal `{...}`, we need square brackets around it.
127+
যদি আমরা অবজেক্ট লিটারেলে `{...}` সিম্বল প্রপার্টি ব্যবহার করতে চাই, এর জন্য আমরা এটি তৃতীয় বন্ধনীর মধ্যে লিখতে হবে।
128128

129-
Like this:
129+
যেমন:
130130

131131
```js
132132
let id = Symbol("id");
@@ -138,13 +138,13 @@ let user = {
138138
*/!*
139139
};
140140
```
141-
That's because we need the value from the variable `id` as the key, not the string "id".
141+
কেননা এটি দ্বারা আমরা নিশ্চিত করতে পারি, এখানের `id` হল একটি সিম্বল টাইপের ভ্যারিয়েবল, প্রপার্টির নাম স্ট্রিং "id" না।
142142

143-
### Symbols are skipped by for..in
143+
### for..in লুপের মধ্যে সিম্বল প্রপার্টি অ্যাক্সেসবল না
144144

145-
Symbolic properties do not participate in `for..in` loop.
145+
সিম্বল প্রপার্টি সমূহ `for..in` লুপের মধ্যে অ্যাক্সেসবল না।
146146

147-
For instance:
147+
যেমন:
148148

149149
```js run
150150
let id = Symbol("id");
@@ -155,16 +155,16 @@ let user = {
155155
};
156156

157157
*!*
158-
for (let key in user) alert(key); // name, age (no symbols)
158+
for (let key in user) alert(key); // name, age (সিম্বল প্রপার্টি দেখাবে না)
159159
*/!*
160160

161-
// the direct access by the symbol works
161+
// তবে সরাসরি এটি অ্যাক্সেসবল
162162
alert( "Direct: " + user[id] );
163163
```
164164

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)` এর জন্যও সিম্বল প্রপার্টি অ্যাক্সেসবল না। কেননা এটি "হাইড সিম্বল প্রপার্টির" নিয়ম মেনে চলে। অন্যথায় অন্য আরেকটি স্ক্রিপ্ট হতে আমাদের অবজেক্টের মধ্যে লুপ চালিয়ে আমরা সিম্বল প্রপার্টির মান জেনে যেতে পারি, যা উচিত নয়।
166166

167-
In contrast, [Object.assign](mdn:js/Object/assign) copies both string and symbol properties:
167+
তবে, [Object.assign](mdn:js/Object/assign) এর ক্ষেত্রে উভয় টাইপের প্রপার্টি কপি হয়, যেমন:
168168

169169
```js run
170170
let id = Symbol("id");
@@ -177,7 +177,7 @@ let clone = Object.assign({}, user);
177177
alert( clone[id] ); // 123
178178
```
179179

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+
তবে এ নিয়ে চিন্তিত হওয়া উচিত নই। কেননা এদের এমনভাবে ডিজাইন করা হয়েছে যেন আমরা কোন অবজেক্টকে ক্লোন বা মার্জ করতে পারি। সাধারণত এজন্য আমরা চাই সকল ধরণের প্রপার্টি(সিম্বল সহ) কপি হোক।
181181

182182
## Global symbols
183183

0 commit comments

Comments
 (0)