Override toString - test

by jonahe

HTML

<h3>
Kind of works? type "AlertByAccess" in the console and you get an alert without ever (explicitly) calling a function, because the toString() method will be called.
But when pasting the below code in another tab, even beginning to type "Al" seems to trigger the alert. (Because "Al" is enough to autocomplete the rest?) So it's probably hard to get the expected behavior if this is used IRL, when typing "Ale" will trigger the function twice
</h3>

JavaScript

let AlertByAccess = function() {
	// empty function
}

AlertByAccess.toString = function() {
	alert("test");
  return "fn:alertByAccess";
}

// Just logging triggers the toString
// console.log(AlertByAccess);