How to use onNet in javascript?

hello im need use onNet in javascript (doc in https://wiki.fivem.net/wiki/List_of_JavaScript_functions)

and my code doesnt work

window.addNetEventListener('eventName' function() {
		onNet('chatMessage', (name, color, message) => {
	  		console.log('chat message received');
		});
});