Imagine a function named foo
that takes two parameters, prints them to a console, and returns a boolean true
if the two parameters are equal:
function foo(a, b) {
console.log([a, b]);
return a === b;
}
A test run produces the following output:
> foo(1, 2);
[1, 2]
false
The decorator accepts
enforces the type of the arguments passed in. It can be used to require the two arguments to string
s and return a boolean
.
decorate(window, "foo", accepts("string", "string"), returns("boolean"));
Now the previous test run will produce an error:
> foo(1, 2);
TypeError: arg 0 does not match string