private-field-details.js (612B)
1 var shouldBeThis; 2 3 class A { 4 #nullReturn = false; 5 constructor(nullReturn) { 6 this.#nullReturn = nullReturn; 7 } 8 9 #calls = 0; 10 11 #z = 12 () => { 13 assertEq(this, shouldBeThis); 14 this.#calls++; 15 16 // To test the second optional below. 17 if (this.#nullReturn && this.#calls == 2) { 18 return null; 19 } 20 21 return this; 22 } 23 24 static chainTest(o) { 25 o?.#z().#z()?.#z(); 26 } 27 }; 28 29 for (var i = 0; i < 1000; i++) { 30 var a = new A(); 31 shouldBeThis = a; 32 33 A.chainTest(a); 34 A.chainTest(null); 35 36 var b = new A(true); 37 shouldBeThis = b; 38 A.chainTest(b); 39 }