Skip to content
Find file
Fetching contributors…
Cannot retrieve contributors at this time
55 lines (45 sloc) 1.51 KB
<html>
<head>
<title>Example</title>
</head>
<body>
<script src="tiptype.js" type="text/javascript" language="JavaScript"></script>
<script src="jquery.js" type="text/javascript" language="JavaScript"></script>
<script type="text/javascript" language="JavaScript">
/**
* It can be this easy. The TipType call is looking at the comments.
*
* If you wanted to see if a was a jQuery object instead, you could replace
* int with jQuery, for example.
*/
function multiply( /*int*/ a, /* number */ b ) {
TipType();
return a*b;
}
console.log(multiply(2, 123)); // ok
console.log(multiply("16",3)); // ok
console.log(multiply(12)); // fails
console.log(multiply('a', 15)); // fails
/**
* Example for complicated notation. Not recommended.
*/
function complicatedMultiply(a, b) {
var checks = [['a', TipType.number, 3], ['b', TipType.number, 13]];
if( checks = TipType.defaults(checks))
return checks;
return a * b;
}
/**
* Example for OTHER complicated notation. Not recommended.
*/
function complicatedMultiply2(a, b) {
var checks = [{'var': 'a', 'type': [TipType.string, TipType.number], 'def': 3},
{'var': 'b', 'type': TipType.number, 'def': 13}];
if( checks = TipType.defaults(checks))
return checks;
return a * b;
}
console.log(complicatedMultiply(2,3)); // will substite default values
</script>
</body>
</html>
Something went wrong with that request. Please try again.