The lodash method _.isArguments exported as a module that checks if value is likely an arguments object.
npx @tessl/cli install tessl/npm-lodash-isarguments@3.1.00
# lodash.isarguments
1
2
The lodash method `_.isArguments` exported as a module that checks if a value is likely an arguments object. This is a modularized version from the lodash utility library that provides reliable cross-browser detection of JavaScript arguments objects.
3
4
## Package Information
5
6
- **Package Name**: lodash.isarguments
7
- **Package Type**: npm
8
- **Language**: JavaScript
9
- **Installation**: `npm install lodash.isarguments`
10
11
## Core Imports
12
13
```javascript
14
var isArguments = require('lodash.isarguments');
15
```
16
17
For ES modules:
18
19
```javascript
20
import isArguments from 'lodash.isarguments';
21
```
22
23
## Basic Usage
24
25
```javascript
26
var isArguments = require('lodash.isarguments');
27
28
// Check arguments objects
29
(function() {
30
console.log(isArguments(arguments)); // => true
31
})(1, 2, 3);
32
33
// Check non-arguments objects
34
console.log(isArguments([1, 2, 3])); // => false
35
console.log(isArguments({})); // => false
36
console.log(isArguments('string')); // => false
37
console.log(isArguments(null)); // => false
38
```
39
40
## Architecture
41
42
The `lodash.isarguments` function implements a robust, cross-browser compatible detection strategy for JavaScript arguments objects:
43
44
**Detection Strategy:**
45
- **Primary Method**: Uses `Object.prototype.toString.call(value) === '[object Arguments]'` when the environment supports native `toStringTag` for arguments objects
46
- **Fallback Method**: In older environments without `toStringTag` support, falls back to checking the `callee` property: `hasOwnProperty.call(value, 'callee') && !propertyIsEnumerable.call(value, 'callee')`
47
48
**Helper Functions:**
49
- **`isObjectLike`**: Pre-filters values to ensure they are objects (`value && typeof value == 'object'`)
50
- **`isLength`**: Validates the length property is a valid array-like length (`typeof value == 'number' && value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER`)
51
52
**Cross-Browser Compatibility:**
53
- Automatically detects environment capabilities via `support.argsTag` feature detection
54
- Seamlessly switches between detection methods without user intervention
55
- Handles edge cases across different JavaScript engines and browser versions
56
57
## Capabilities
58
59
### Arguments Object Detection
60
61
Checks if a value is likely an arguments object using cross-browser compatible detection methods.
62
63
```javascript { .api }
64
/**
65
* Checks if `value` is likely an `arguments` object.
66
*
67
* @param {*} value - Any JavaScript value to test for arguments object characteristics.
68
* Accepts primitives, objects, arrays, functions, null, undefined, etc.
69
* @returns {boolean} Returns `true` when value is a genuine arguments object from a function call,
70
* `false` for all other values including arrays, plain objects, and primitives.
71
*
72
* @example
73
* // Arguments object detection
74
* (function() { return isArguments(arguments); })(); // => true
75
*
76
* @example
77
* // Non-arguments objects
78
* isArguments([1, 2, 3]); // => false (array)
79
* isArguments({ '0': 1, length: 1 }); // => false (plain object)
80
*/
81
function isArguments(value)
82
```
83
84
**Parameters:**
85
- `value` (*): The value to check
86
87
**Returns:**
88
- (`boolean`): Returns `true` if value is correctly classified as an arguments object, else `false`
89
90
**Implementation Details:**
91
92
The function implements a sophisticated dual-path detection algorithm:
93
94
**Primary Detection (Modern Environments):**
95
- Uses `Object.prototype.toString.call(value) === '[object Arguments]'` when `support.argsTag` is available
96
- Relies on native JavaScript engine support for arguments object `toStringTag`
97
- Combined with `isObjectLike(value)` pre-filtering and `isLength(value.length)` validation
98
99
**Fallback Detection (Legacy Environments):**
100
- Activates when `!support.argsTag` (older browsers/engines without native arguments detection)
101
- Checks `hasOwnProperty.call(value, 'callee')` - arguments objects have a `callee` property
102
- Validates `!propertyIsEnumerable.call(value, 'callee')` - `callee` should not be enumerable
103
- Still uses `isObjectLike()` and `isLength()` helper validation
104
105
**Helper Function Roles:**
106
- **`isObjectLike(value)`**: Ensures `value && typeof value == 'object'` to filter out primitives
107
- **`isLength(value.length)`**: Validates length as valid array-like index (`number`, `>= 0`, integer, `<= MAX_SAFE_INTEGER`)
108
- **Feature Detection**: `support.argsTag` determines which detection path to use automatically
109
110
**Edge Cases:**
111
- Returns `false` for arrays, even though they have similar structure
112
- Returns `false` for objects that mimic arguments structure (e.g., `{ '0': 1, 'callee': function() {}, 'length': 1 }`)
113
- Returns `false` for all primitive values (strings, numbers, booleans)
114
- Returns `false` for `null` and `undefined`
115
- Works correctly with arguments objects from different realms/frames
116
117
**Usage Examples:**
118
119
```javascript
120
var isArguments = require('lodash.isarguments');
121
122
// Real arguments object
123
(function() {
124
return isArguments(arguments); // => true
125
})();
126
127
// Array (false positive check)
128
isArguments([1, 2, 3]); // => false
129
130
// Object that looks like arguments
131
isArguments({
132
'0': 1,
133
'callee': function() {},
134
'length': 1
135
}); // => false
136
137
// Primitive values
138
isArguments('string'); // => false
139
isArguments(42); // => false
140
isArguments(true); // => false
141
isArguments(null); // => false
142
isArguments(undefined); // => false
143
144
// Other objects
145
isArguments(new Date()); // => false
146
isArguments(new Error()); // => false
147
isArguments(/regex/); // => false
148
isArguments(function() {}); // => false
149
```