1 The `in` operator tests keys along the whole prototype chain, but it never 2 dispatches `__get__`: a property which exists only as a virtual one is not 3 visible to `in`. 4 5 -- Testcase -- 6 {% 7 let o = proto({ own: 1 }, { 8 inherited: 2, 9 __get__(key) { 10 return "virtual"; 11 } 12 }); 13 14 print("own" in o, " ", "inherited" in o, " ", "virtual" in o, " ", "__get__" in o, "\n"); 15 %} 16 -- End -- 17 18 -- Expect stdout -- 19 true true false true 20 -- End -- 21 22 For arrays, `in` tests element values first and keys of the prototype chain 23 second, without dispatching a metamethod either. 24 25 -- Testcase -- 26 {% 27 let a = proto([1, 2], { 28 named: 3, 29 __get__(key) { 30 return "virtual"; 31 } 32 }); 33 34 print(1 in a, " ", 3 in a, " ", "named" in a, " ", "virtual" in a, "\n"); 35 %} 36 -- End -- 37 38 -- Expect stdout -- 39 true false true false 40 -- End --
This page was automatically generated by LXR 0.3.1. • OpenWrt