Add global helper

This commit is contained in:
ReimarPB 2023-09-09 13:46:41 +02:00
parent cc2e2587f3
commit 9faf3c9260
2 changed files with 7 additions and 7 deletions

View File

@ -1,13 +1,10 @@
<script src="runtime-checker.js"></script>
<script>
function sum(a_number, b_number) {
const sum = typedFunction((a_number, b_number) => {
return a + b;
}
});
// I need to get rid of this
sum = sum.addRuntimeChecker();
var result = sum(1, 2);
const result = sum(1, 2);
console.log(result); // 3
sum("1", 2); // Error

View File

@ -1,7 +1,6 @@
Function.prototype.addRuntimeChecker = function() {
var handler = {
apply: function(target, thisArg, argumentValues) {
// https://stackoverflow.com/a/31194949
var argumentNames = target.toString()
.replace(/[/][/].*$/mg,'') // strip single-line comments
@ -56,3 +55,7 @@ Function.prototype.addRuntimeChecker = function() {
return new Proxy(this, handler);
}
window.typedFunction = function(func) {
return func.addRuntimeChecker();
}