MIRROR: javascript for 馃悳's, a tiny runtime with big ambitions
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

at master 34 lines 872 B view raw
1// Debug native function binding 2 3const target = new EventTarget(); 4 5console.log('target:', target); 6console.log('typeof target:', typeof target); 7 8const addEventListenerFn = target.addEventListener; 9console.log('\naddEventListenerFn:', addEventListenerFn); 10console.log('typeof addEventListenerFn:', typeof addEventListenerFn); 11 12console.log('\nTrying to call it directly:'); 13try { 14 addEventListenerFn.call(target, 'test', () => { 15 console.log('Direct call worked!'); 16 }); 17 target.dispatchEvent('test'); 18} catch (e) { 19 console.log('Error:', e); 20} 21 22console.log('\nTrying to bind it:'); 23try { 24 const bound = addEventListenerFn.bind(target); 25 console.log('bound:', bound); 26 console.log('typeof bound:', typeof bound); 27 28 bound('test', () => { 29 console.log('Bound call worked!'); 30 }); 31 target.dispatchEvent('test'); 32} catch (e) { 33 console.log('Error:', e); 34}