GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

No menu could be recovered. Follow the blue links in the page.

This view

  • Original page
  • New address

GeezerVison is showing fa.javascript.info — فراخوانی محتوای یک آرایه

  • آموزش
  • زبان جاوااسکریپت
  • انواع داده
  • آرایه‌ها
بازگشت به درس

فراخوانی محتوای یک آرایه

اهمیت: 5

نتیجه چه خواهد بود؟ چرا؟

let arr = ["a", "b"];

arr.push(function() {
  alert( this );
});

arr[2](); // ?

صدازدن arr[2]() از لحاظ سینتکس همان obj[method]() قدیم است، ما arr را در نقش obj داریم و 2 در نقش method.

پس صدازدن تابع arr[2] مانند متد یک شیء است. به طور طبیعی، این تابع this را درحالی که به شیء arr رجوع می‌کند می‌گیرد و آرایه را نمایش می‌دهد:

let arr = ["a", "b"];

arr.push(function() {
  alert( this );
})

arr[2](); // a,b,function(){...}

آرایه 3 مقدار دارد: در ابتدا 2 مقدار داشت سپس تابع اضافه شد.

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.