Skip to content

Use Rest Parameters where it makes sense #637

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 12, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/.jshintrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"browser": true,
"esnext": true,

"bitwise": true,
"boss": true,
Expand Down
2 changes: 1 addition & 1 deletion src/core/ReactComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ var ReactComponent = {
},

/**
* Base constructor for all React component.
* Base constructor for all React components.
*
* Subclasses that override this method should make sure to invoke
* `ReactComponent.Mixin.construct.call(this, ...)`.
Expand Down
7 changes: 3 additions & 4 deletions src/core/ReactCompositeComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -1156,7 +1156,7 @@ var ReactCompositeComponentMixin = {
boundMethod.__reactBoundArguments = null;
var componentName = component.constructor.displayName;
var _bind = boundMethod.bind;
boundMethod.bind = function(newThis) {
boundMethod.bind = function(newThis, ...args) {
// User is trying to bind() an autobound method; we effectively will
// ignore the value of "this" that the user is trying to use, so
// let's warn.
Expand All @@ -1165,7 +1165,7 @@ var ReactCompositeComponentMixin = {
'bind(): React component methods may only be bound to the ' +
'component instance. See ' + componentName
);
} else if (arguments.length === 1) {
} else if (!args.length) {
console.warn(
'bind(): You are binding a component method to the component. ' +
'React does this for you automatically in a high-performance ' +
Expand All @@ -1176,8 +1176,7 @@ var ReactCompositeComponentMixin = {
var reboundMethod = _bind.apply(boundMethod, arguments);
reboundMethod.__reactBoundContext = component;
reboundMethod.__reactBoundMethod = method;
reboundMethod.__reactBoundArguments =
Array.prototype.slice.call(arguments, 1);
reboundMethod.__reactBoundArguments = args;
return reboundMethod;
};
}
Expand Down
12 changes: 6 additions & 6 deletions src/test/ReactDefaultPerf.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,19 +187,19 @@ if (__DEV__) {

var fnArgs = _getFnArguments(func);

return function() {
return function(...args) {
var timeBeforeFn = performanceNow();
var fnReturn = func.apply(this, arguments);
var fnReturn = func.apply(this, args);
var timeAfterFn = performanceNow();

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

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

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

Expand Down
10 changes: 3 additions & 7 deletions src/vendor/error/ex.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,9 @@
* @param {string} errorMessage
*/

var ex = function(errorMessage/*, arg1, arg2, ...*/) {
var args = Array.prototype.slice.call(arguments).map(function(arg) {
return String(arg);
});
var expectedLength = errorMessage.split('%s').length - 1;

if (expectedLength !== args.length - 1) {
var ex = function(...args) {
args = args.map((arg) => String(arg));
if (args[0].split('%s').length !== args.length) {
// something wrong with the formatting string
return ex('ex args number mismatch: %s', JSON.stringify(args));
}
Expand Down