Node properties: type, tag and contents by msisaifu · Pull Request #187 · javascript-tutorial/bn.javascript.info
@@ -1,40 +1,40 @@
We can see which class it belongs by outputting it, like: আমরা এভাবে এর ক্লাস নামটি দেখতে পারি:
```js run alert(document); // [object HTMLDocument] ```
Or: অথবা:
```js run alert(document.constructor.name); // HTMLDocument ```
So, `document` is an instance of `HTMLDocument` class. সুতরাং, `document` হল `HTMLDocument` ক্লাসের ইন্সট্যান্স।
What's its place in the hierarchy? চলুন হায়ার্য়াকি অনুযায়ী আরো বিস্তারিত দেখি
Yeah, we could browse the specification, but it would be faster to figure out manually. আমরা স্পেসিফিকেশন দেখে এই ব্যাপারে জানতে পারি, কিন্তু আমরা কোড করেও এর বিস্তারিত দেখতে পারি।
Let's traverse the prototype chain via `__proto__`. চলুন আমরা `__proto__` প্রটোটাইপ চেইন ট্রাভার্স করি।
As we know, methods of a class are in the `prototype` of the constructor. For instance, `HTMLDocument.prototype` has methods for documents. আমরা জানি, ক্লাসের মেথডসমূহ `prototype` দ্বারা constructor কে নির্দেশিত করে। যেমন, `HTMLDocument.prototype` এ ডকুমেন্ট এর মেথড আছে।
Also, there's a reference to the constructor function inside the `prototype`: এছাড়াও, `prototype` এর constructor এ এর উল্লেখ আছে:
```js run alert(HTMLDocument.prototype.constructor === HTMLDocument); // true ```
To get a name of the class as a string, we can use `constructor.name`. Let's do it for the whole `document` prototype chain, till class `Node`: ক্লাস নামটিকে কে আমরা স্ট্রিং আকারে পেতে, `constructor.name` ব্যবহার করতে পারি। চলুন আমরা `document` এর প্রটোটাইপ চেইন ট্রাভার্স করি, যতক্ষণ পর্যন্ত `Node` ক্লাসটি না পায়:
```js run alert(HTMLDocument.prototype.constructor.name); // HTMLDocument alert(HTMLDocument.prototype.__proto__.constructor.name); // Document alert(HTMLDocument.prototype.__proto__.__proto__.constructor.name); // Node ```
That's the hierarchy. এটিই document এর হায়ার্য়াকি।
We also could examine the object using `console.dir(document)` and see these names by opening `__proto__`. The console takes them from `constructor` internally. আমরা `console.dir(document)` এর সাহায্যেও দেখতে পারি, এবং `__proto__` তে ক্লিক করে প্রত্যেকটির নাম দেখতে পাব। কনসোল ইন্টার্নালি `constructor` সমূহ নেয়।
We can see which class it belongs by outputting it, like: আমরা এভাবে এর ক্লাস নামটি দেখতে পারি:
```js run alert(document); // [object HTMLDocument] ```
Or: অথবা:
```js run alert(document.constructor.name); // HTMLDocument ```
So, `document` is an instance of `HTMLDocument` class. সুতরাং, `document` হল `HTMLDocument` ক্লাসের ইন্সট্যান্স।
What's its place in the hierarchy? চলুন হায়ার্য়াকি অনুযায়ী আরো বিস্তারিত দেখি
Yeah, we could browse the specification, but it would be faster to figure out manually. আমরা স্পেসিফিকেশন দেখে এই ব্যাপারে জানতে পারি, কিন্তু আমরা কোড করেও এর বিস্তারিত দেখতে পারি।
Let's traverse the prototype chain via `__proto__`. চলুন আমরা `__proto__` প্রটোটাইপ চেইন ট্রাভার্স করি।
As we know, methods of a class are in the `prototype` of the constructor. For instance, `HTMLDocument.prototype` has methods for documents. আমরা জানি, ক্লাসের মেথডসমূহ `prototype` দ্বারা constructor কে নির্দেশিত করে। যেমন, `HTMLDocument.prototype` এ ডকুমেন্ট এর মেথড আছে।
Also, there's a reference to the constructor function inside the `prototype`: এছাড়াও, `prototype` এর constructor এ এর উল্লেখ আছে:
```js run alert(HTMLDocument.prototype.constructor === HTMLDocument); // true ```
To get a name of the class as a string, we can use `constructor.name`. Let's do it for the whole `document` prototype chain, till class `Node`: ক্লাস নামটিকে কে আমরা স্ট্রিং আকারে পেতে, `constructor.name` ব্যবহার করতে পারি। চলুন আমরা `document` এর প্রটোটাইপ চেইন ট্রাভার্স করি, যতক্ষণ পর্যন্ত `Node` ক্লাসটি না পায়:
```js run alert(HTMLDocument.prototype.constructor.name); // HTMLDocument alert(HTMLDocument.prototype.__proto__.constructor.name); // Document alert(HTMLDocument.prototype.__proto__.__proto__.constructor.name); // Node ```
That's the hierarchy. এটিই document এর হায়ার্য়াকি।
We also could examine the object using `console.dir(document)` and see these names by opening `__proto__`. The console takes them from `constructor` internally. আমরা `console.dir(document)` এর সাহায্যেও দেখতে পারি, এবং `__proto__` তে ক্লিক করে প্রত্যেকটির নাম দেখতে পাব। কনসোল ইন্টার্নালি `constructor` সমূহ নেয়।