কীভাবে এটি document.querySelectorAll('a')একটি
NodeList থেকে নিয়মিত অ্যারে রূপান্তর করে ?
এটি আমাদের কাছে কোড যা
[].slice.call(document.querySelectorAll('a'), 0)
প্রথমে এটি ভেঙে ফেলা যাক,
[] // Array object
.slice // Accessing the function 'slice' present in the prototype of Array
.call // Accessing the function 'call' present in the prototype of function object(slice)
(document.querySelectorAll('a'),0)
// 'call' can have arguments like, (thisArg, arg1,arg2...n).
// So here we are passing the 'thisArg' as an array like object,
// that is a 'nodeList'. It will be served as 'this' object inside of slice function.
// And finally setting 'start' argument of slice as '0' and leaving the 'end'
// argument as 'undefined'
ধাপ: 1 এক্সেকিউশন callফাংশন
- ভিতরে
call, thisArgবাদে বাকী সমস্ত যুক্তি যুক্তির তালিকায় যুক্ত হবে।
- এখন ফাংশনটি
sliceতার thisমান হিসাবে
thisArg(বস্তুর মতো অ্যারে থেকে এসেছে document.querySelector) এবং যুক্তি তালিকার সাথে আবদ্ধ করে চলবে । অর্থাত্] যুক্তি startযা ধারণ করে0
পদক্ষেপ: 2 sliceফাংশন সম্পাদনের ভিতরে আবেদন করাcall
পিএস আমাদের পরিস্থিতি আরও ভাল করে বোঝার জন্য আমাদের প্রসঙ্গে প্রয়োজনীয় কয়েকটি পদক্ষেপ কল এবং স্লাইজের মূল অ্যালগরিদম থেকে উপেক্ষা করা হয়েছে ।
Array.prototype.slice.call(document.querySelectorAll('a'));আপনার লিখিত কোডের খণ্ডটি লেখার একটি সঠিক উপায়।