Add global helper
This commit is contained in:
parent
cc2e2587f3
commit
9faf3c9260
@ -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
|
||||
|
@ -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();
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user