Skip to content

Commit 7c95194

Browse files
committed
Merge pull request facebook#637 from cpojer/use-rest-params
Use Rest Parameters where it makes sense
2 parents 8b0af9b + decb49a commit 7c95194

File tree

5 files changed

+14
-18
lines changed

5 files changed

+14
-18
lines changed

src/.jshintrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"browser": true,
3+
"esnext": true,
34

45
"bitwise": true,
56
"boss": true,

src/core/ReactComponent.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ var ReactComponent = {
276276
},
277277

278278
/**
279-
* Base constructor for all React component.
279+
* Base constructor for all React components.
280280
*
281281
* Subclasses that override this method should make sure to invoke
282282
* `ReactComponent.Mixin.construct.call(this, ...)`.

src/core/ReactCompositeComponent.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1159,7 +1159,7 @@ var ReactCompositeComponentMixin = {
11591159
boundMethod.__reactBoundArguments = null;
11601160
var componentName = component.constructor.displayName;
11611161
var _bind = boundMethod.bind;
1162-
boundMethod.bind = function(newThis) {
1162+
boundMethod.bind = function(newThis, ...args) {
11631163
// User is trying to bind() an autobound method; we effectively will
11641164
// ignore the value of "this" that the user is trying to use, so
11651165
// let's warn.
@@ -1168,7 +1168,7 @@ var ReactCompositeComponentMixin = {
11681168
'bind(): React component methods may only be bound to the ' +
11691169
'component instance. See ' + componentName
11701170
);
1171-
} else if (arguments.length === 1) {
1171+
} else if (!args.length) {
11721172
console.warn(
11731173
'bind(): You are binding a component method to the component. ' +
11741174
'React does this for you automatically in a high-performance ' +
@@ -1179,8 +1179,7 @@ var ReactCompositeComponentMixin = {
11791179
var reboundMethod = _bind.apply(boundMethod, arguments);
11801180
reboundMethod.__reactBoundContext = component;
11811181
reboundMethod.__reactBoundMethod = method;
1182-
reboundMethod.__reactBoundArguments =
1183-
Array.prototype.slice.call(arguments, 1);
1182+
reboundMethod.__reactBoundArguments = args;
11841183
return reboundMethod;
11851184
};
11861185
}

src/test/ReactDefaultPerf.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -187,19 +187,19 @@ if (__DEV__) {
187187

188188
var fnArgs = _getFnArguments(func);
189189

190-
return function() {
190+
return function(...args) {
191191
var timeBeforeFn = performanceNow();
192-
var fnReturn = func.apply(this, arguments);
192+
var fnReturn = func.apply(this, args);
193193
var timeAfterFn = performanceNow();
194194

195195
/**
196196
* Hold onto arguments in a readable way: args[1] -> args.component.
197197
* args is also passed to the callback, so if you want to save an
198198
* argument in the log, do so in the callback.
199199
*/
200-
var args = {};
201-
for (var i = 0; i < arguments.length; i++) {
202-
args[fnArgs[i]] = arguments[i];
200+
var argsObject = {};
201+
for (var i = 0; i < args.length; i++) {
202+
argsObject[fnArgs[i]] = args[i];
203203
}
204204

205205
var log = {
@@ -224,7 +224,7 @@ if (__DEV__) {
224224
* - the wrapped method's info object.
225225
*/
226226
var callback = _getCallback(objName, fnName);
227-
callback && callback(this, args, fnReturn, log, info);
227+
callback && callback(this, argsObject, fnReturn, log, info);
228228

229229
log.timing.timeToLog = performanceNow() - timeAfterFn;
230230

src/vendor/error/ex.js

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,9 @@
2929
* @param {string} errorMessage
3030
*/
3131

32-
var ex = function(errorMessage/*, arg1, arg2, ...*/) {
33-
var args = Array.prototype.slice.call(arguments).map(function(arg) {
34-
return String(arg);
35-
});
36-
var expectedLength = errorMessage.split('%s').length - 1;
37-
38-
if (expectedLength !== args.length - 1) {
32+
var ex = function(...args) {
33+
args = args.map((arg) => String(arg));
34+
if (args[0].split('%s').length !== args.length) {
3935
// something wrong with the formatting string
4036
return ex('ex args number mismatch: %s', JSON.stringify(args));
4137
}

0 commit comments

Comments
 (0)