Through "proxy" function, to check the arguments type. It is different from the static methods such as TypeScript and is only used as a lightweight runtime arguments checking function.
npm install rtcpThrough "proxy" function, to check the arguments type. It is different from the static methods such as TypeScript and is only used as a lightweight runtime arguments checking function.
number / string / boolean / null / array / date / regexp / function / undefined / NaN / Infinity
``sh`
$ npm i rtcp --save
or download RTCP.min.js
`html`
`jsfunction ${ name }
RTCP.fail(( name, fail ) => {
console.error( , fail );
})
function X ( x ) {
console.log( x + 1 );
}
function Y ( x, y ) {
console.log( x + y );
}
RTCP( X, 'number' )( 1 );
RTCP( X, 'number|string' )( '1' );
RTCP( X, 'number' )( '1' ); // fail
RTCP( Y, [ 'number', 'number' ] )( 1, 1 );
RTCP( Y, [ 'number', 'number' ] )( 1, '1' ); // fail
`
`jshello, ${ name }
class X {
@RTCP( 'string' )
hello ( name ) {
console.log( );
}
}
( new X() ).hello( 'foo' );
( new X() ).hello(); // fail
``