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 uz.javascript.info — array[-1] ga murojaat

  • Qo'llanma
  • JavaScript dasturlash tili
  • Boshqalar
  • Proxy va Reflect
darsga qaytish

array[-1] ga murojaat

Ba’zi dasturlash tillarida biz massiv elementlariga oxiridan boshlab manfiy indekslar yordamida kirishimiz mumkin.

Bu kabi:

let array = [1, 2, 3];

array[-1]; // 3, oxirgi element
array[-2]; // 2, oxiridan bir qadam oldingi
array[-3]; // 1, oxiridan ikki qadam oldingi

Boshqacha qilib aytganda, array[-N] array[array.uzunligi - N] bilan bir xil.

Ushbu xatti-harakatni amalga oshirish uchun proksi-server yarating.

Bu shunday ishlashi kerak:

let array = [1, 2, 3];

array = new Proxy(array, {
  /* sizning kodingiz */
});

alert(array[-1]); // 3
alert(array[-2]); // 2

// Massivning boshqa funksiyalari "xuddi shunday" saqlanishi kerak
let array = [1, 2, 3];

array = new Proxy(array, {
  get(target, prop, receiver) {
    if (prop < 0) {
      // biz unga arr [1] kabi kirsak ham
      // prop - bu satr, shuning uchun uni raqamga aylantirish kerak
      prop = +prop + target.length;
    }
    return Reflect.get(target, prop, receiver);
  },
});

alert(array[-1]); // 3
alert(array[-2]); // 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.