README.md (2480B)
1 <!-- 2 3 @license Apache-2.0 4 5 Copyright (c) 2018 The Stdlib Authors. 6 7 Licensed under the Apache License, Version 2.0 (the "License"); 8 you may not use this file except in compliance with the License. 9 You may obtain a copy of the License at 10 11 http://www.apache.org/licenses/LICENSE-2.0 12 13 Unless required by applicable law or agreed to in writing, software 14 distributed under the License is distributed on an "AS IS" BASIS, 15 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 See the License for the specific language governing permissions and 17 limitations under the License. 18 19 --> 20 21 # isNativeFunction 22 23 > Test if a value is a native function. 24 25 <section class="intro"> 26 27 Native functions execute native code that is typically not written in JavaScript, but a lower-level language like C++. This includes the JavaScript [built-in functions][mdn-builtins], functions implemented using [Node.js C/C++ addons][node-js-add-ons], and code compiled via [WebAssembly][webassembly]. 28 29 </section> 30 31 <!-- /.intro --> 32 33 <section class="usage"> 34 35 ## Usage 36 37 ```javascript 38 var isNativeFunction = require( '@stdlib/assert/is-native-function' ); 39 ``` 40 41 #### isNativeFunction( value ) 42 43 Tests if a `value` is a native `function`. 44 45 ```javascript 46 var bool = isNativeFunction( Date ); 47 // returns true 48 49 function beep() { 50 console.log( 'beep' ); 51 } 52 53 bool = isNativeFunction( beep ); 54 // returns false 55 ``` 56 57 </section> 58 59 <!-- /.usage --> 60 61 <section class="examples"> 62 63 ## Examples 64 65 <!-- eslint-disable no-empty-function, no-restricted-syntax, stdlib/no-builtin-math --> 66 67 <!-- eslint no-undef: "error" --> 68 69 ```javascript 70 var isNativeFunction = require( '@stdlib/assert/is-native-function' ); 71 72 var bool = isNativeFunction( Math.sqrt ); 73 // returns true 74 75 bool = isNativeFunction( Date ); 76 // returns true 77 78 bool = isNativeFunction( RegExp ); 79 // returns true 80 81 bool = isNativeFunction( function foo() {} ); 82 // returns false 83 84 bool = isNativeFunction( 'beep' ); 85 // returns false 86 87 bool = isNativeFunction( 5 ); 88 // returns false 89 90 bool = isNativeFunction( true ); 91 // returns false 92 93 bool = isNativeFunction( null ); 94 // returns false 95 96 bool = isNativeFunction( [] ); 97 // returns false 98 99 bool = isNativeFunction( {} ); 100 // returns false 101 ``` 102 103 </section> 104 105 <!-- /.examples --> 106 107 <section class="links"> 108 109 [mdn-builtins]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects 110 111 [node-js-add-ons]: https://nodejs.org/api/addons.html 112 113 [webassembly]: https://webassembly.org/ 114 115 </section> 116 117 <!-- /.links -->