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
Export and import statements that we covered in previous chapters are called "static". The syntax is very simple and strict.
3
+
আগের অধ্যায়ে আমরা ইমপোর্ট এবং এক্সপোর্ট নিয়ে আলোচনা করেছি যাদের "static" বলা হয়। যার সিনট্যাক্স খুবই সাধারন।
4
4
5
-
First, we can't dynamically generate any parameters of `import`.
5
+
প্রথমত, `import` এর কোন প্যারামিটার ডাইনামিক ভাবে আমরা জেনারেট করতে পারি না।
6
6
7
-
The module path must be a primitive string, can't be a function call. This won't work:
7
+
মডিউলের পাথ অবশ্যই প্রিমিটিভ স্ট্রিং হতে হবে, ফাংশন কল হওয়া যাবে না। এটি কাজ করবে নাঃ
8
8
9
9
```js
10
-
import ... from*!*getModuleName()*/!*; //Error, only from "string" is allowed
10
+
import ... from*!*getModuleName()*/!*; //এরর, শুধুমাত্র "string" প্রযোজ্য
11
11
```
12
12
13
-
Second, we can't import conditionally or at run-time:
13
+
দ্বিতীয়ত, আমরা কন্ডিশনালি অথবা রান-টাইমে ইমপোর্ট করতে পারবো না।
14
14
15
15
```js
16
16
if(...) {
17
-
import ...; //Error, not allowed!
17
+
import ...; //এরর, এটি প্রযোজ্য নয়।
18
18
}
19
19
20
20
{
21
-
import ...; //Error, we can't put import in any block
21
+
import ...; //এরর, আমারা কোন ব্লকের মধ্যে ইমপোর্ট রাখতে পারি না।
22
22
}
23
23
```
24
24
25
-
That's because`import`/`export`aim to provide a backbone for the code structure. That's a good thing, as code structure can be analyzed, modules can be gathered and bundled into one file by special tools, unused exports can be removed ("tree-shaken"). That's possible only because the structure of imports/exports is simple and fixed.
25
+
তার কারন`import`/`export`এর উদ্দেশ্য হচ্ছে কোডের গঠনে মেরুদন্ডের ন্যায় কাজ করা। এটি একটি ভালো দিক, কোডের গঠন বিশ্লেষণ করে দেখা যায়, একটি বিশেষ টুলের দ্বারা মডিউল গুলোকে ফাইলে একসাথে রাখা যায়, অব্যবহৃত এক্সপোর্ট গুলো রিমুভ("tree-shaken") করা যায়. `imports/exports` এর সাধারন গঠনের কারনেই এটি সম্ভব হয়।
26
26
27
-
But how can we import a module dynamically, on-demand?
27
+
কিন্তু, প্রয়োজনে একটি মডিউলকে কিভাবে আমরা ডাইনামিকালি ইমপোর্ট করতে পারি?
28
28
29
-
## The import() expression
29
+
## import() এক্সপ্রেশন
30
30
31
-
The `import(module)`expression loads the module and returns a promise that resolves into a module object that contains all its exports. It can be called from any place in the code.
31
+
`import(module)`এক্সপ্রেশনটি মডিউলকে লোড করে এবং একটি প্রমিস রিটার্ন করে যা একটি মডিউল অবজেক্টের মধ্যে রিসল্ভ হয়ে থাকে এবং এতে সমস্ত এক্সপোর্ট গুলো থাকে।
32
32
33
-
We can use it dynamically in any place of the code, for instance:
33
+
আমরা কোডের যে কোন জায়গায় এটি ডাইনামিকালি ব্যবহার করতে পারি, যেমনঃ
34
34
35
35
```js
36
-
let modulePath =prompt("Which module to load?");
36
+
let modulePath =prompt("কোন মডিউলটি লোড করতে চান?");
37
37
38
38
import(modulePath)
39
39
.then(obj=><module object>)
40
-
.catch(err=><loading error, e.g. if no such module>)
40
+
.catch(err=><লোডিং এরর, যদি কোন মডিউল না থাকে>)
41
41
```
42
42
43
-
Or, we could use `let module = await import(modulePath)`if inside an async function.
43
+
অথবা, যদি এটি একটি `async` ফাংশনের ভিতর হয়ে থাকে তবে `let module = await import(modulePath)`ব্যবহার করতে পারি।
44
44
45
-
For instance, if we have the following module `say.js`:
45
+
যেমন, আমাদের যদি নিম্নলিখিত মডিউল থাকে `say.js`:
46
46
47
47
```js
48
48
// 📁 say.js
@@ -55,7 +55,7 @@ export function bye() {
55
55
}
56
56
```
57
57
58
-
...Then dynamic import can be like this:
58
+
...তবে ডাইনামিক ইমপোর্টটি হতে পারেঃ
59
59
60
60
```js
61
61
let {hi, bye} =awaitimport('./say.js');
@@ -64,35 +64,35 @@ hi();
64
64
bye();
65
65
```
66
66
67
-
Or, if`say.js`has the default export:
67
+
অথবা, যদি`say.js`এর ডিফল্ট এক্সপোর্ট থাকেঃ
68
68
69
69
```js
70
70
// 📁 say.js
71
71
exportdefaultfunction() {
72
-
alert("Module loaded (export default)!");
72
+
alert("মডিউল লোড হয়েছে (export default)!");
73
73
}
74
74
```
75
75
76
-
...Then, in order to access it, we can use `default`property of the module object:
76
+
...তারপর এটাকে এক্সেস করার জন্য আমরা মডিউল অব্জেক্টের `default`প্রপার্টি ব্যাবহার করতে পারি।
77
77
78
78
```js
79
79
let obj =awaitimport('./say.js');
80
80
let say =obj.default;
81
-
//or, in one line: let {default: say} = await import('./say.js');
81
+
//অথাবা, এক লাইনে: let {default: say} = await import('./say.js');
82
82
83
83
say();
84
84
```
85
85
86
-
Here's the full example:
86
+
এখানে সম্পূর্ণ উদাহারনটি রয়েছেঃ
87
87
88
88
[codetabs src="say" current="index.html"]
89
89
90
90
```smart
91
-
Dynamic imports work in regular scripts, they don't require `script type="module"`.
91
+
রেগুলার স্ক্রিপ্টে ডাইনামিক ইমপোর্ট কাজ করে, তার জন্য `script type="module" প্রয়োজন হয় না।
92
92
```
93
93
94
94
```smart
95
-
Although `import()` looks like a function call, it's a special syntax that just happens to use parentheses (similar to `super()`).
95
+
যদিও `import()` দেখতে ফাংশন কলের মতো, কিন্তু এটি একটি (`super()` মতো) বিশেষ সিন্টেক্স যার জন্য "parentheses" ব্যবহার করতে হয়। `).
96
96
97
-
So we can't copy `import` to a variable or use `call/apply` with it. That's not a function.
97
+
তাই আমারা `import` কে কোন ভেরিয়েবলে কপি অথবা `call/apply` করতে পারি না।
0 commit comments