2 * lodash 3.9.1 (Custom Build) <https://lodash.com/>
3 * Build: `lodash modern modularize exports="npm" -o ./`
4 * Copyright 2012-2015 The Dojo Foundation <http://dojofoundation.org/>
5 * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
6 * Copyright 2009-2015 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
7 * Available under MIT license <https://lodash.com/license>
10 /** `Object#toString` result references. */
11 var funcTag = '[object Function]';
13 /** Used to detect host constructors (Safari > 5). */
14 var reIsHostCtor = /^\[object .+?Constructor\]$/;
17 * Checks if `value` is object-like.
20 * @param {*} value The value to check.
21 * @returns {boolean} Returns `true` if `value` is object-like, else `false`.
23 function isObjectLike(value) {
24 return !!value && typeof value == 'object';
27 /** Used for native method references. */
28 var objectProto = Object.prototype;
30 /** Used to resolve the decompiled source of functions. */
31 var fnToString = Function.prototype.toString;
33 /** Used to check objects for own properties. */
34 var hasOwnProperty = objectProto.hasOwnProperty;
37 * Used to resolve the [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring)
40 var objToString = objectProto.toString;
42 /** Used to detect if a method is native. */
43 var reIsNative = RegExp('^' +
44 fnToString.call(hasOwnProperty).replace(/[\\^$.*+?()[\]{}|]/g, '\\$&')
45 .replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$'
49 * Gets the native function at `key` of `object`.
52 * @param {Object} object The object to query.
53 * @param {string} key The key of the method to get.
54 * @returns {*} Returns the function if it's native, else `undefined`.
56 function getNative(object, key) {
57 var value = object == null ? undefined : object[key];
58 return isNative(value) ? value : undefined;
62 * Checks if `value` is classified as a `Function` object.
67 * @param {*} value The value to check.
68 * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
74 * _.isFunction(/abc/);
77 function isFunction(value) {
78 // The use of `Object#toString` avoids issues with the `typeof` operator
79 // in older versions of Chrome and Safari which return 'function' for regexes
80 // and Safari 8 equivalents which return 'object' for typed array constructors.
81 return isObject(value) && objToString.call(value) == funcTag;
85 * Checks if `value` is the [language type](https://es5.github.io/#x8) of `Object`.
86 * (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
91 * @param {*} value The value to check.
92 * @returns {boolean} Returns `true` if `value` is an object, else `false`.
98 * _.isObject([1, 2, 3]);
104 function isObject(value) {
105 // Avoid a V8 JIT bug in Chrome 19-20.
106 // See https://code.google.com/p/v8/issues/detail?id=2291 for more details.
107 var type = typeof value;
108 return !!value && (type == 'object' || type == 'function');
112 * Checks if `value` is a native function.
117 * @param {*} value The value to check.
118 * @returns {boolean} Returns `true` if `value` is a native function, else `false`.
121 * _.isNative(Array.prototype.push);
127 function isNative(value) {
131 if (isFunction(value)) {
132 return reIsNative.test(fnToString.call(value));
134 return isObjectLike(value) && reIsHostCtor.test(value);
137 module.exports = getNative;