jsduck 3.0.pre → 3.0.pre2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +21 -229
- data/Rakefile +31 -17
- data/bin/jsduck +1 -0
- data/js-classes/Array.js +561 -0
- data/js-classes/Boolean.js +110 -0
- data/js-classes/Date.js +999 -0
- data/js-classes/Function.js +256 -0
- data/js-classes/Number.js +308 -0
- data/js-classes/Object.js +404 -0
- data/js-classes/RegExp.js +415 -0
- data/js-classes/String.js +1034 -0
- data/jsduck.gemspec +2 -2
- data/lib/jsduck/accessors.rb +71 -0
- data/lib/jsduck/aggregator.rb +14 -2
- data/lib/jsduck/app.rb +6 -5
- data/lib/jsduck/class_formatter.rb +12 -8
- data/lib/jsduck/css_parser.rb +2 -2
- data/lib/jsduck/doc_formatter.rb +2 -2
- data/lib/jsduck/doc_parser.rb +32 -25
- data/lib/jsduck/exporter.rb +1 -1
- data/lib/jsduck/guides.rb +11 -2
- data/lib/jsduck/js_parser.rb +30 -8
- data/lib/jsduck/merger.rb +31 -16
- data/lib/jsduck/options.rb +93 -15
- data/lib/jsduck/renderer.rb +40 -3
- data/lib/jsduck/search_data.rb +8 -5
- data/lib/jsduck/source_file.rb +5 -4
- data/lib/jsduck/type_parser.rb +7 -6
- metadata +17 -5
- data/example.js +0 -144
@@ -0,0 +1,256 @@
|
|
1
|
+
/**
|
2
|
+
* @class Function
|
3
|
+
*
|
4
|
+
* Every function in JavaScript is actually a `Function` object.
|
5
|
+
*
|
6
|
+
* `Function` objects created with the `Function` constructor are parsed when the
|
7
|
+
* function is created. This is less efficient than declaring a function and
|
8
|
+
* calling it within your code, because functions declared with the function
|
9
|
+
* statement are parsed with the rest of the code.
|
10
|
+
*
|
11
|
+
* All arguments passed to the function are treated as the names of the
|
12
|
+
* identifiers of the parameters in the function to be created, in the order in
|
13
|
+
* which they are passed.
|
14
|
+
*
|
15
|
+
* Invoking the `Function` constructor as a function (without using the `new`
|
16
|
+
* operator) has the same effect as invoking it as a constructor.
|
17
|
+
*
|
18
|
+
* # Specifying arguments with the `Function` constructor
|
19
|
+
*
|
20
|
+
* The following code creates a `Function` object that takes two arguments.
|
21
|
+
*
|
22
|
+
* // Example can be run directly in your JavaScript console
|
23
|
+
*
|
24
|
+
* // Create a function that takes two arguments and returns the sum of those
|
25
|
+
* arguments
|
26
|
+
* var adder = new Function("a", "b", "return a + b");
|
27
|
+
*
|
28
|
+
* // Call the function
|
29
|
+
* adder(2, 6);
|
30
|
+
* // > 8
|
31
|
+
*
|
32
|
+
* The arguments "a" and "b" are formal argument names that are used in the
|
33
|
+
* function body, "return a + b".
|
34
|
+
*
|
35
|
+
* <div class="notice">
|
36
|
+
* Documentation for this class comes from <a href="https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Function">MDN</a>
|
37
|
+
* and is available under <a href="http://creativecommons.org/licenses/by-sa/2.0/">Creative Commons: Attribution-Sharealike license</a>.
|
38
|
+
* </div>
|
39
|
+
*/
|
40
|
+
|
41
|
+
/**
|
42
|
+
* @method constructor
|
43
|
+
* Creates new Function object.
|
44
|
+
*
|
45
|
+
* @param {String...} args
|
46
|
+
* Names to be used by the function as formal argument names. Each must be a
|
47
|
+
* string that corresponds to a valid JavaScript identifier or a list of such
|
48
|
+
* strings separated with a comma; for example "`x`", "`theValue`", or "`a,b`".
|
49
|
+
* @param {String} functionBody
|
50
|
+
* A string containing the JavaScript statements comprising the function
|
51
|
+
* definition.
|
52
|
+
*/
|
53
|
+
|
54
|
+
// Properties
|
55
|
+
|
56
|
+
/**
|
57
|
+
* @property {Number} length
|
58
|
+
* Specifies the number of arguments expected by the function.
|
59
|
+
*/
|
60
|
+
|
61
|
+
//Methods
|
62
|
+
|
63
|
+
/**
|
64
|
+
* @method apply
|
65
|
+
* Applies the method of another object in the context of a different object (the
|
66
|
+
* calling object); arguments can be passed as an Array object.
|
67
|
+
*
|
68
|
+
* You can assign a different this object when calling an existing function. `this` refers to the
|
69
|
+
* current object, the calling object. With `apply`, you can write a method once and then inherit it
|
70
|
+
* in another object, without having to rewrite the method for the new object.
|
71
|
+
*
|
72
|
+
* `apply` is very similar to call, except for the type of arguments it supports. You can use an
|
73
|
+
* arguments array instead of a named set of parameters. With apply, you can use an array literal, for
|
74
|
+
* example, `fun.apply(this, ['eat', 'bananas'])`, or an Array object, for example, `fun.apply(this,
|
75
|
+
* new Array('eat', 'bananas'))`.
|
76
|
+
*
|
77
|
+
* You can also use arguments for the `argsArray` parameter. `arguments` is a local variable of a
|
78
|
+
* function. It can be used for all unspecified arguments of the called object. Thus, you do not have
|
79
|
+
* to know the arguments of the called object when you use the `apply` method. You can use arguments
|
80
|
+
* to pass all the arguments to the called object. The called object is then responsible for handling
|
81
|
+
* the arguments.
|
82
|
+
*
|
83
|
+
* Since ECMAScript 5th Edition you can also use any kind of object which is array like, so in
|
84
|
+
* practice this means it's going to have a property length and integer properties in the range
|
85
|
+
* `[0...length)`. As an example you can now use a NodeList or a own custom object like `{'length': 2,
|
86
|
+
* '0': 'eat', '1': 'bananas'}`.
|
87
|
+
*
|
88
|
+
* You can use `apply` to chain constructors for an object, similar to Java. In the following example,
|
89
|
+
* the constructor for the `Product` object is defined with two parameters, `name` and `value`. Two
|
90
|
+
* other functions `Food` and `Toy` invoke `Product` passing `this` and `arguments`. `Product`
|
91
|
+
* initializes the properties `name` and `price`, both specialized functions define the category. In
|
92
|
+
* this example, the `arguments` object is fully passed to the product constructor and corresponds to
|
93
|
+
* the two defined parameters.
|
94
|
+
*
|
95
|
+
* function Product(name, price) {
|
96
|
+
* this.name = name;
|
97
|
+
* this.price = price;
|
98
|
+
*
|
99
|
+
* if (price < 0)
|
100
|
+
* throw RangeError('Cannot create product "' + name + '" with a negative price');
|
101
|
+
* return this;
|
102
|
+
* }
|
103
|
+
*
|
104
|
+
* function Food(name, price) {
|
105
|
+
* Product.apply(this, arguments);
|
106
|
+
* this.category = 'food';
|
107
|
+
* }
|
108
|
+
* Food.prototype = new Product();
|
109
|
+
*
|
110
|
+
* function Toy(name, price) {
|
111
|
+
* Product.apply(this, arguments);
|
112
|
+
* this.category = 'toy';
|
113
|
+
* }
|
114
|
+
* Toy.prototype = new Product();
|
115
|
+
*
|
116
|
+
* var cheese = new Food('feta', 5);
|
117
|
+
* var fun = new Toy('robot', 40);
|
118
|
+
*
|
119
|
+
* Clever usage of `apply` allows you to use built-ins functions for some tasks that otherwise
|
120
|
+
* probably would have been written by looping over the array values. As an example here we are going
|
121
|
+
* to use Math.max/Math.min to find out the maximum/minimum value in an array.
|
122
|
+
*
|
123
|
+
* //min/max number in an array
|
124
|
+
* var numbers = [5, 6, 2, 3, 7];
|
125
|
+
*
|
126
|
+
* //using Math.min/Math.max apply
|
127
|
+
* var max = Math.max.apply(null, numbers); // This about equal to Math.max(numbers[0], ...) or
|
128
|
+
* // Math.max(5, 6, ..)
|
129
|
+
* var min = Math.min.apply(null, numbers);
|
130
|
+
*
|
131
|
+
* //vs. simple loop based algorithm
|
132
|
+
* max = -Infinity, min = +Infinity;
|
133
|
+
*
|
134
|
+
* for (var i = 0; i < numbers.length; i++) {
|
135
|
+
* if (numbers[i] > max)
|
136
|
+
* max = numbers[i];
|
137
|
+
* if (numbers[i] < min)
|
138
|
+
* min = numbers[i];
|
139
|
+
* }
|
140
|
+
*
|
141
|
+
* But beware: in using `apply` this way, you run the risk of exceeding the JavaScript engine's
|
142
|
+
* argument length limit. The consequences of applying a function with too many arguments (think more
|
143
|
+
* than tens of thousands of arguments) vary across engines, because the limit (indeed even the nature
|
144
|
+
* of any excessively-large-stack behavior) is unspecified. Some engines will throw an exception. More
|
145
|
+
* perniciously, others will arbitrarily limit the number of arguments actually passed to the applied
|
146
|
+
* function. (To illustrate this latter case: if such an engine had a limit of four arguments [actual
|
147
|
+
* limits are of course significantly higher], it would be as if the arguments 5, 6, 2, 3 had been
|
148
|
+
* passed to apply in the examples above, rather than the full array.) If your value array might grow
|
149
|
+
* into the tens of thousands, use a hybrid strategy: apply your function to chunks of the array at a
|
150
|
+
* time:
|
151
|
+
*
|
152
|
+
* function minOfArray(arr)
|
153
|
+
* {
|
154
|
+
* var min = Infinity;
|
155
|
+
* var QUANTUM = 32768;
|
156
|
+
* for (var i = 0, len = arr.length; i < len; i += QUANTUM)
|
157
|
+
* {
|
158
|
+
* var submin = Math.min.apply(null, numbers.slice(i, Math.min(i + QUANTUM, len)));
|
159
|
+
* min = Math.min(submin, min);
|
160
|
+
* }
|
161
|
+
* return min;
|
162
|
+
* }
|
163
|
+
*
|
164
|
+
* var min = minOfArray([5, 6, 2, 3, 7]);
|
165
|
+
*
|
166
|
+
* @param {Object} thisArg The value of this provided for the call to fun. Note that this may not be
|
167
|
+
* the actual value seen by the method: if the method is a function in non-strict mode code, null and
|
168
|
+
* undefined will be replaced with the global object, and primitive values will be boxed.
|
169
|
+
* @param {Array} argsArray An array like object, specifying the arguments with which fun should be
|
170
|
+
* called, or null or undefined if no arguments should be provided to the function.
|
171
|
+
* @return {Object} Returns what the function returns.
|
172
|
+
*/
|
173
|
+
|
174
|
+
/**
|
175
|
+
* @method call
|
176
|
+
* Calls (executes) a method of another object in the context of a different
|
177
|
+
* object (the calling object); arguments can be passed as they are.
|
178
|
+
*
|
179
|
+
* You can assign a different this object when calling an existing function. `this` refers to the
|
180
|
+
* current object, the calling object.
|
181
|
+
*
|
182
|
+
* With `call`, you can write a method once and then inherit it in another object, without having to
|
183
|
+
* rewrite the method for the new object.
|
184
|
+
*
|
185
|
+
* You can use call to chain constructors for an object, similar to Java. In the following example,
|
186
|
+
* the constructor for the product object is defined with two parameters, name and value. Another
|
187
|
+
* object, `prod_dept`, initializes its unique variable (`dept`) and calls the constructor for
|
188
|
+
* `product` in its constructor to initialize the other variables.
|
189
|
+
*
|
190
|
+
* function Product(name, price) {
|
191
|
+
* this.name = name;
|
192
|
+
* this.price = price;
|
193
|
+
*
|
194
|
+
* if (price < 0)
|
195
|
+
* throw RangeError('Cannot create product "' + name + '" with a negative price');
|
196
|
+
* return this;
|
197
|
+
* }
|
198
|
+
*
|
199
|
+
* function Food(name, price) {
|
200
|
+
* Product.call(this, name, price);
|
201
|
+
* this.category = 'food';
|
202
|
+
* }
|
203
|
+
* Food.prototype = new Product();
|
204
|
+
*
|
205
|
+
* function Toy(name, price) {
|
206
|
+
* Product.call(this, name, price);
|
207
|
+
* this.category = 'toy';
|
208
|
+
* }
|
209
|
+
* Toy.prototype = new Product();
|
210
|
+
*
|
211
|
+
* var cheese = new Food('feta', 5);
|
212
|
+
* var fun = new Toy('robot', 40);
|
213
|
+
*
|
214
|
+
* In this purely constructed example, we create anonymous function and use `call` to invoke it on
|
215
|
+
* every object in an array. The main purpose of the anonymous function here is to add a print
|
216
|
+
* function to every object, which is able to print the right index of the object in the array.
|
217
|
+
* Passing the object as `this` value was not strictly necessary, but is done for explanatory purpose.
|
218
|
+
*
|
219
|
+
* var animals = [
|
220
|
+
* {species: 'Lion', name: 'King'},
|
221
|
+
* {species: 'Whale', name: 'Fail'}
|
222
|
+
* ];
|
223
|
+
*
|
224
|
+
* for (var i = 0; i < animals.length; i++) {
|
225
|
+
* (function (i) {
|
226
|
+
* this.print = function () {
|
227
|
+
* console.log('#' + i + ' ' + this.species + ': ' + this.name);
|
228
|
+
* }
|
229
|
+
* }).call(animals[i], i);
|
230
|
+
* }
|
231
|
+
*
|
232
|
+
* @param {Object} thisArg The value of this provided for the call to `fun`.Note that this may not be
|
233
|
+
* the actual value seen by the method: if the method is a function in non-strict mode code, `null`
|
234
|
+
* and `undefined` will be replaced with the global object, and primitive values will be boxed.
|
235
|
+
* @param {Object...} args Arguments for the object.
|
236
|
+
* @return {Object} Returns what the function returns.
|
237
|
+
*/
|
238
|
+
|
239
|
+
/**
|
240
|
+
* @method toString
|
241
|
+
* Returns a string representing the source code of the function. Overrides the
|
242
|
+
* `Object.toString` method.
|
243
|
+
*
|
244
|
+
* The {@link Function} object overrides the `toString` method of the Object object; it does
|
245
|
+
* not inherit Object.toString. For `Function` objects, the `toString` method returns a string
|
246
|
+
* representation of the object.
|
247
|
+
*
|
248
|
+
* JavaScript calls the `toString` method automatically when a `Function` is to be represented as a
|
249
|
+
* text value or when a Function is referred to in a string concatenation.
|
250
|
+
*
|
251
|
+
* For `Function` objects, the built-in `toString` method decompiles the function back into the
|
252
|
+
* JavaScript source that defines the function. This string includes the `function` keyword, the
|
253
|
+
* argument list, curly braces, and function body.
|
254
|
+
*
|
255
|
+
* @return {String} The function as a string.
|
256
|
+
*/
|
@@ -0,0 +1,308 @@
|
|
1
|
+
/**
|
2
|
+
* @class Number
|
3
|
+
*
|
4
|
+
* Creates a wrapper object to allow you to work with numerical values.
|
5
|
+
*
|
6
|
+
* The primary uses for the `Number` object are:
|
7
|
+
*
|
8
|
+
* If the argument cannot be converted into a number, it returns `NaN`.
|
9
|
+
*
|
10
|
+
* In a non-constructor context (i.e., without the `new` operator), `Number` can
|
11
|
+
* be used to perform a type conversion.
|
12
|
+
*
|
13
|
+
* # Using the `Number` object to assign values to numeric variables
|
14
|
+
*
|
15
|
+
* The following example uses the `Number` object's properties to assign values to
|
16
|
+
* several numeric variables:
|
17
|
+
*
|
18
|
+
* biggestNum = Number.MAX_VALUE;
|
19
|
+
* smallestNum = Number.MIN_VALUE;
|
20
|
+
* infiniteNum = Number.POSITIVE_INFINITY;
|
21
|
+
* negInfiniteNum = Number.NEGATIVE_INFINITY;
|
22
|
+
* notANum = Number.NaN;
|
23
|
+
*
|
24
|
+
* # Using `Number` to convert a `Date` object
|
25
|
+
*
|
26
|
+
* The following example converts the `Date` object to a numerical value using
|
27
|
+
* `Number` as a function:
|
28
|
+
*
|
29
|
+
* var d = new Date("December 17, 1995 03:24:00");
|
30
|
+
* print(Number(d));
|
31
|
+
*
|
32
|
+
* This displays "819199440000".
|
33
|
+
*
|
34
|
+
* The following example converts the Date object to a numerical value using
|
35
|
+
* `Number` as a function:
|
36
|
+
*
|
37
|
+
* <div class="notice">
|
38
|
+
* Documentation for this class comes from <a href="https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Number">MDN</a>
|
39
|
+
* and is available under <a href="http://creativecommons.org/licenses/by-sa/2.0/">Creative Commons: Attribution-Sharealike license</a>.
|
40
|
+
* </div>
|
41
|
+
*/
|
42
|
+
|
43
|
+
/**
|
44
|
+
* @method constructor
|
45
|
+
* Creates new Number object.
|
46
|
+
* @param value
|
47
|
+
* The numeric value of the object being created.
|
48
|
+
*/
|
49
|
+
|
50
|
+
//Properties
|
51
|
+
|
52
|
+
/**
|
53
|
+
* @property {Number} MAX_VALUE
|
54
|
+
* @static
|
55
|
+
* The largest positive representable number. The largest negative representable
|
56
|
+
* number is `-MAX_VALUE`.
|
57
|
+
*
|
58
|
+
* The `MAX_VALUE` property has a value of approximately 1.79E+308. Values larger than `MAX_VALUE` are
|
59
|
+
* represented as `"Infinity"`.
|
60
|
+
*
|
61
|
+
* Because `MAX_VALUE` is a static property of `Number`, you always use it as `Number.MAX_VALUE`,
|
62
|
+
* rather than as a property of a `Number` object you created.
|
63
|
+
*
|
64
|
+
* The following code multiplies two numeric values. If the result is less than or equal to
|
65
|
+
* `MAX_VALUE`, the `func1` function is called; otherwise, the `func2` function is called.
|
66
|
+
*
|
67
|
+
* if (num1 * num2 <= Number.MAX_VALUE)
|
68
|
+
* func1();
|
69
|
+
* else
|
70
|
+
* func2();
|
71
|
+
*/
|
72
|
+
|
73
|
+
/**
|
74
|
+
* @property {Number} MIN_VALUE
|
75
|
+
* @static
|
76
|
+
* The smallest positive representable number -- that is, the positive number
|
77
|
+
* closest to zero (without actually being zero). The smallest negative
|
78
|
+
* representable number is `-MIN_VALUE`.
|
79
|
+
*
|
80
|
+
* The `MIN_VALUE` property is the number closest to 0, not the most negative number, that JavaScript
|
81
|
+
* can represent.
|
82
|
+
*
|
83
|
+
* `MIN_VALUE` has a value of approximately 5e-324. Values smaller than `MIN_VALUE` ("underflow
|
84
|
+
* values") are converted to 0.
|
85
|
+
*
|
86
|
+
* Because `MIN_VALUE` is a static property of `Number`, you always use it as `Number.MIN_VALUE`,
|
87
|
+
* rather than as a property of a `Number` object you created.
|
88
|
+
*
|
89
|
+
* The following code divides two numeric values. If the result is greater than or equal to
|
90
|
+
* `MIN_VALUE`, the `func1` function is called; otherwise, the `func2` function is called.
|
91
|
+
*
|
92
|
+
* if (num1 / num2 >= Number.MIN_VALUE)
|
93
|
+
* func1()
|
94
|
+
* else
|
95
|
+
* func2()
|
96
|
+
*/
|
97
|
+
|
98
|
+
/**
|
99
|
+
* @property {Number} NaN
|
100
|
+
* @static
|
101
|
+
* Special "not a number" value.
|
102
|
+
*/
|
103
|
+
|
104
|
+
/**
|
105
|
+
* @property {Number} NEGATIVE_INFINITY
|
106
|
+
* Special value representing negative infinity; returned on overflow.
|
107
|
+
*
|
108
|
+
* The value of `Number.NEGATIVE_INFINITY` is the same as the negative value of the global object's
|
109
|
+
* Infinity property.
|
110
|
+
*
|
111
|
+
* This value behaves slightly differently than mathematical infinity:
|
112
|
+
*
|
113
|
+
* * Any positive value, including POSITIVE_INFINITY, multiplied by NEGATIVE_INFINITY is NEGATIVE_INFINITY.
|
114
|
+
* * Any negative value, including NEGATIVE_INFINITY, multiplied by NEGATIVE_INFINITY is
|
115
|
+
* POSITIVE_INFINITY.
|
116
|
+
* * Zero multiplied by NEGATIVE_INFINITY is NaN.
|
117
|
+
* * NaN multiplied by NEGATIVE_INFINITY is NaN.
|
118
|
+
* * NEGATIVE_INFINITY, divided by any negative value except NEGATIVE_INFINITY, is
|
119
|
+
* POSITIVE_INFINITY.
|
120
|
+
* * NEGATIVE_INFINITY, divided by any positive value except POSITIVE_INFINITY, is
|
121
|
+
* NEGATIVE_INFINITY.
|
122
|
+
* * NEGATIVE_INFINITY, divided by either NEGATIVE_INFINITY or POSITIVE_INFINITY, is NaN.
|
123
|
+
* * Any number divided by NEGATIVE_INFINITY is Zero.
|
124
|
+
*
|
125
|
+
* Several JavaScript methods (such as the `Number` constructor, `parseFloat`, and `parseInt`) return
|
126
|
+
* `NaN` if the value specified in the parameter is significantly lower than `Number.MIN_VALUE`.
|
127
|
+
*
|
128
|
+
* You might use the `Number.NEGATIVE_INFINITY` property to indicate an error condition that returns a
|
129
|
+
* finite number in case of success. Note, however, that `isFinite` would be more appropriate in such
|
130
|
+
* a case.
|
131
|
+
*
|
132
|
+
* In the following example, the variable smallNumber is assigned a value that is smaller than the
|
133
|
+
* minimum value. When the `if` statement executes, `smallNumber` has the value `"-Infinity"`, so
|
134
|
+
* `smallNumber` is set to a more manageable value before continuing.
|
135
|
+
*
|
136
|
+
* var smallNumber = (-Number.MAX_VALUE) * 2
|
137
|
+
* if (smallNumber == Number.NEGATIVE_INFINITY) {
|
138
|
+
* smallNumber = returnFinite();
|
139
|
+
* }
|
140
|
+
*/
|
141
|
+
|
142
|
+
/**
|
143
|
+
* @property {Number} POSITIVE_INFINITY
|
144
|
+
* Special value representing infinity; returned on overflow.
|
145
|
+
*
|
146
|
+
* The value of `Number.POSITIVE_INFINITY` is the same as the value of the global object's Infinity
|
147
|
+
* property.
|
148
|
+
*
|
149
|
+
* This value behaves slightly differently than mathematical infinity:
|
150
|
+
*
|
151
|
+
* * Any positive value, including POSITIVE_INFINITY, multiplied by POSITIVE_INFINITY is
|
152
|
+
* POSITIVE_INFINITY.
|
153
|
+
* * Any negative value, including NEGATIVE_INFINITY, multiplied by POSITIVE_INFINITY is
|
154
|
+
* NEGATIVE_INFINITY.
|
155
|
+
* * Zero multiplied by POSITIVE_INFINITY is NaN.
|
156
|
+
* * NaN multiplied by POSITIVE_INFINITY is NaN.
|
157
|
+
* * POSITIVE_INFINITY, divided by any negative value except NEGATIVE_INFINITY, is
|
158
|
+
* NEGATIVE_INFINITY.
|
159
|
+
* * POSITIVE_INFINITY, divided by any positive value except POSITIVE_INFINITY, is
|
160
|
+
* POSITIVE_INFINITY.
|
161
|
+
* * POSITIVE_INFINITY, divided by either NEGATIVE_INFINITY or POSITIVE_INFINITY, is NaN.
|
162
|
+
* * Any number divided by POSITIVE_INFINITY is Zero.
|
163
|
+
*
|
164
|
+
* Several JavaScript methods (such as the `Number` constructor, `parseFloat`, and `parseInt`) return
|
165
|
+
* `NaN` if the value specified in the parameter is significantly higher than `Number.MAX_VALUE`.
|
166
|
+
*
|
167
|
+
* You might use the `Number.POSITIVE_INFINITY` property to indicate an error condition that returns a
|
168
|
+
* finite number in case of success. Note, however, that `isFinite` would be more appropriate in such
|
169
|
+
* a case.
|
170
|
+
*
|
171
|
+
* In the following example, the variable `bigNumber` is assigned a value that is larger than the
|
172
|
+
* maximum value. When the if statement executes, `bigNumber` has the value "Infinity", so `bigNumber`
|
173
|
+
* is set to a more manageable value before continuing.
|
174
|
+
*
|
175
|
+
* var bigNumber = Number.MAX_VALUE * 2
|
176
|
+
* if (bigNumber == Number.POSITIVE_INFINITY) {
|
177
|
+
* bigNumber = returnFinite();
|
178
|
+
* }
|
179
|
+
*/
|
180
|
+
|
181
|
+
//Methods
|
182
|
+
|
183
|
+
/**
|
184
|
+
* @method toExponential
|
185
|
+
* Returns a string representing the number in exponential notation.
|
186
|
+
*
|
187
|
+
* A string representing a `Number` object in exponential notation with one digit before the decimal
|
188
|
+
* point, rounded to `fractionDigits` digits after the decimal point. If the `fractionDigits` argument
|
189
|
+
* is omitted, the number of digits after the decimal point defaults to the number of digits necessary
|
190
|
+
* to represent the value uniquely.
|
191
|
+
*
|
192
|
+
* If you use the `toExponential` method for a numeric literal and the numeric literal has no exponent
|
193
|
+
* and no decimal point, leave a space before the dot that precedes the method call to prevent the dot
|
194
|
+
* from being interpreted as a decimal point.
|
195
|
+
*
|
196
|
+
* If a number has more digits that requested by the `fractionDigits` parameter, the number is rounded
|
197
|
+
* to the nearest number represented by `fractionDigits` digits. See the discussion of rounding in the
|
198
|
+
* description of the `toFixed` method, which also applies to `toExponential`.
|
199
|
+
*
|
200
|
+
* var num=77.1234;
|
201
|
+
*
|
202
|
+
* alert("num.toExponential() is " + num.toExponential()); //displays 7.71234e+1
|
203
|
+
*
|
204
|
+
* alert("num.toExponential(4) is " + num.toExponential(4)); //displays 7.7123e+1
|
205
|
+
*
|
206
|
+
* alert("num.toExponential(2) is " + num.toExponential(2)); //displays 7.71e+1
|
207
|
+
*
|
208
|
+
* alert("77.1234.toExponential() is " + 77.1234.toExponential()); //displays 7.71234e+1
|
209
|
+
*
|
210
|
+
* alert("77 .toExponential() is " + 77 .toExponential()); //displays 7.7e+1
|
211
|
+
*
|
212
|
+
* @param {Number} fractionDigits An integer specifying the number of digits after the decimal
|
213
|
+
* point. Defaults to as many digits as necessary to specify the number.
|
214
|
+
* @return {String} Exponential notation of number.
|
215
|
+
*/
|
216
|
+
|
217
|
+
/**
|
218
|
+
* @method toFixed
|
219
|
+
* Returns a string representing the number in fixed-point notation.
|
220
|
+
*
|
221
|
+
* @return {String} A string representation of `number` that does not use
|
222
|
+
* exponential notation and has exactly `digits` digits after the decimal place.
|
223
|
+
* The number is rounded if necessary, and the fractional part is padded with
|
224
|
+
* zeros if necessary so that it has the specified length. If `number` is greater
|
225
|
+
* than 1e+21, this method simply calls `Number.toString()` and returns a string
|
226
|
+
* in exponential notation.
|
227
|
+
*
|
228
|
+
* @param {Number} digits The number of digits to appear after the decimal point; this may be a
|
229
|
+
* value between 0 and 20, inclusive, and implementations may optionally support a larger range of
|
230
|
+
* values. If this argument is omitted, it is treated as 0.
|
231
|
+
*/
|
232
|
+
|
233
|
+
/**
|
234
|
+
* @method toLocaleString
|
235
|
+
* Returns a human readable string representing the number using the locale of the
|
236
|
+
* environment. Overrides the `Object.prototype.toLocaleString` method.
|
237
|
+
*
|
238
|
+
* This method available to numbers will convert the number into a string which is suitable for
|
239
|
+
* presentation in the given locale.
|
240
|
+
*
|
241
|
+
* var number = 3500
|
242
|
+
* console.log(number.toLocaleString()); // Displays "3,500" in English locale
|
243
|
+
*
|
244
|
+
* @return {String} String representing the number.
|
245
|
+
*/
|
246
|
+
|
247
|
+
/**
|
248
|
+
* @method toPrecision
|
249
|
+
* Returns a string representing the number to a specified precision in fixed-
|
250
|
+
* point or exponential notation.
|
251
|
+
*
|
252
|
+
* A string representing a `Number` object in fixed-point or
|
253
|
+
* exponential notation rounded to precision significant digits. See the
|
254
|
+
* discussion of rounding in the description of the `toFixed` method, which also
|
255
|
+
* applies to `toPrecision`.
|
256
|
+
*
|
257
|
+
* If the precision argument is omitted, behaves as Number.toString. If it is a
|
258
|
+
* non-integer value, it is rounded to the nearest integer. After rounding, if
|
259
|
+
* that value is not between 1 and 100 (inclusive), a RangeError is thrown.
|
260
|
+
*
|
261
|
+
* @param {Number} precision An integer specifying the number of significant digits.
|
262
|
+
* @return {String} String that represents `Number` object.
|
263
|
+
*/
|
264
|
+
|
265
|
+
/**
|
266
|
+
* @method toString
|
267
|
+
* Returns a string representing the specified object. Overrides the
|
268
|
+
* `Object.prototype.toString` method.
|
269
|
+
*
|
270
|
+
* The `Number` object overrides the `toString` method of the `Object` object; it does not inherit
|
271
|
+
* `Object.toString`. For `Number` objects, the toString method returns a string representation of the
|
272
|
+
* object in the specified radix.
|
273
|
+
*
|
274
|
+
* The `toString` method parses its first argument, and attempts to return a string representation in
|
275
|
+
* the specified radix (base). For radixes above 10, the letters of the alphabet indicate numerals
|
276
|
+
* greater than 9. For example, for hexadecimal numbers (base 16), A through F are used.
|
277
|
+
*
|
278
|
+
* If `toString` is given a radix not between 2 and 36, an exception is thrown.
|
279
|
+
*
|
280
|
+
* If the radix is not specified, JavaScript assumes the preferred radix is 10.
|
281
|
+
*
|
282
|
+
* var count = 10;
|
283
|
+
* print(count.toString()); // displays "10"
|
284
|
+
* print((17).toString()); // displays "17"
|
285
|
+
*
|
286
|
+
* var x = 7;
|
287
|
+
* print(x.toString(2)); // displays "111"
|
288
|
+
*
|
289
|
+
* @param {Number} radix An integer between 2 and 36 specifying the base to use for representing
|
290
|
+
* numeric values.
|
291
|
+
* @return {String} The number represented as a string.
|
292
|
+
*/
|
293
|
+
|
294
|
+
/**
|
295
|
+
* @method valueOf
|
296
|
+
* Returns the primitive value of the specified object. Overrides the
|
297
|
+
* `Object.prototype.valueOf` method.
|
298
|
+
*
|
299
|
+
* The `valueOf` method of `Number` returns the primitive value of a `Number` object as a number data
|
300
|
+
* type.
|
301
|
+
*
|
302
|
+
* This method is usually called internally by JavaScript and not explicitly in code.
|
303
|
+
*
|
304
|
+
* var x = new Number();
|
305
|
+
* print(x.valueOf()); // prints "0"
|
306
|
+
*
|
307
|
+
* @return {Number} The primitive value of the number.
|
308
|
+
*/
|