1 The "this" object accesses the current function context. 2 3 -- Expect stdout -- 4 true 5 true 6 -- End -- 7 8 -- Testcase -- 9 {% 10 // Functions not invoked on objects have no this context 11 function test() { 12 return (this === null); 13 } 14 15 // When invoked, "this" will point to the object containing the function 16 let o; 17 o = { 18 test: function() { 19 return (this === o); 20 } 21 }; 22 23 print(test(), "\n"); 24 print(o.test(), "\n"); 25 %} 26 -- End -- 27 28 Test that the context is properly restored if function call arguments are 29 dot or bracket expressions as well. 30 31 -- Expect stdout -- 32 true 33 true 34 -- End -- 35 36 -- Testcase -- 37 {% 38 let o; 39 o = { 40 test: function() { 41 return (this === o); 42 } 43 }; 44 45 let dummy = { foo: true, bar: false }; 46 47 print(o.test(dummy.foo, dummy.bar), "\n"); 48 print(o.test(dummy.foo, o.test(dummy.foo, dummy.bar)), "\n"); 49 %} 50 -- End --
This page was automatically generated by LXR 0.3.1. • OpenWrt