Add global helper
This commit is contained in:
parent
cc2e2587f3
commit
9faf3c9260
@ -1,13 +1,10 @@
|
|||||||
<script src="runtime-checker.js"></script>
|
<script src="runtime-checker.js"></script>
|
||||||
<script>
|
<script>
|
||||||
function sum(a_number, b_number) {
|
const sum = typedFunction((a_number, b_number) => {
|
||||||
return a + b;
|
return a + b;
|
||||||
}
|
});
|
||||||
|
|
||||||
// I need to get rid of this
|
const result = sum(1, 2);
|
||||||
sum = sum.addRuntimeChecker();
|
|
||||||
|
|
||||||
var result = sum(1, 2);
|
|
||||||
console.log(result); // 3
|
console.log(result); // 3
|
||||||
|
|
||||||
sum("1", 2); // Error
|
sum("1", 2); // Error
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
Function.prototype.addRuntimeChecker = function() {
|
Function.prototype.addRuntimeChecker = function() {
|
||||||
var handler = {
|
var handler = {
|
||||||
apply: function(target, thisArg, argumentValues) {
|
apply: function(target, thisArg, argumentValues) {
|
||||||
|
|
||||||
// https://stackoverflow.com/a/31194949
|
// https://stackoverflow.com/a/31194949
|
||||||
var argumentNames = target.toString()
|
var argumentNames = target.toString()
|
||||||
.replace(/[/][/].*$/mg,'') // strip single-line comments
|
.replace(/[/][/].*$/mg,'') // strip single-line comments
|
||||||
@ -56,3 +55,7 @@ Function.prototype.addRuntimeChecker = function() {
|
|||||||
return new Proxy(this, handler);
|
return new Proxy(this, handler);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
window.typedFunction = function(func) {
|
||||||
|
return func.addRuntimeChecker();
|
||||||
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user