fa
Feedback
Web_programming

Web_programming

رفتن به کانال در Telegram

Sharif web programming If you have any questions, please feel free to ask(@yumcoder)

نمایش بیشتر
1 052
مشترکین
+124 ساعت
اطلاعاتی وجود ندارد7 روز
-530 روز
آرشیو پست ها
نمودار زمان انیمشین ch05-02
نمودار زمان انیمشین ch05-02

کد فوق و کدهای زیر در جلسه فردا ارزیابی خواهیم کرد. در ادامه Timing functions های مختلف آورده شده است

Call and apply are pretty interchangeable. Just decide whether it’s easier to send in an array or a comma separated list of arguments. I always remember which one is which by remembering that Call is for comma (separated list) and Apply is for Array. Bind is a bit different. It returns a new function. Call and Apply execute the current function immediately. Bind is great for a lot of things. We can use it to curry functions like in the above example. We can take a simple hello function and turn it into a helloJon or helloKelly. We can also use it for events like onClick where we don’t know when they’ll be fired but we know what context we want them to have.

photo content

photo content

photo content

- Call invokes the function and allows you to pass in arguments one by one. - Apply invokes the function and allows you to pass in arguments as an array. - Bind returns a new function, allowing you to pass in a this array and any number of arguments.

هنگامی که بر روی یک button کلیک می شود event به div می رسد و آن onclick را فرامیخواند. onclick به bounded متصل شده است. پس آن فراخوانی می شود در هنگام اجرای بدنه bounded مقدار this برابر است با div و درون این متد that و context بکار گرفته می شوند به خط return that.apply(context,newArgs); توجه کتید. به عبارت دیگر درون این متد اساسا کاری با this نداریم 😊 پس به درستی context را تغییر داده ایم

photo content

ابتدای جلسه شنبه این اسلاید را یکبار دیگر با هم مرور خواهیم کرد.

همان طور که در این متد می بینید با فراخوانی این متد تابع that با this = context فراخوانی می شود

هنگامی که بر روی یک المان کلیک می کنید از طریق تکنیک bubbling - صفحه ۲۱۱- event کلیک به div می رسد که این خود به متد bounded متصل شده است و آن را اجرا می کند

photo content

حال در شکل زیر ارتباطات مشخص شده است

پیاده سازی نوعی متد bind در js
پیاده سازی نوعی متد bind در js

صفحه ۲۱۷ - برنامه مطرح شده در کلاس. در ادامه جزییات پیاده سازی bind آورده شده است. درک این قطعه کد برای reactjs لازم است. زیر
صفحه ۲۱۷ - برنامه مطرح شده در کلاس. در ادامه جزییات پیاده سازی bind آورده شده است. درک این قطعه کد برای reactjs لازم است. زیرا در انجا نیز این syntax استفاده می شود

اسلاید ۵ - نسخه دوم