From f1508c49371dd050c09c1ae39d02fb9a5542e6ef Mon Sep 17 00:00:00 2001 From: Ben Alpert Date: Thu, 24 Jul 2014 12:11:19 -0700 Subject: [PATCH] Use .bind when autobinding This eliminates all of the `boundMethod` frames from call stacks when debugging and as far as I know should behave the same otherwise. Test Plan: jest --- src/core/ReactCompositeComponent.js | 4 +--- src/core/__tests__/ReactCompositeComponentError-test.js | 2 +- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/core/ReactCompositeComponent.js b/src/core/ReactCompositeComponent.js index 637c6613a0..42a1dcb45b 100644 --- a/src/core/ReactCompositeComponent.js +++ b/src/core/ReactCompositeComponent.js @@ -1265,9 +1265,7 @@ var ReactCompositeComponentMixin = { */ _bindAutoBindMethod: function(method) { var component = this; - var boundMethod = function() { - return method.apply(component, arguments); - }; + var boundMethod = method.bind(component); if (__DEV__) { boundMethod.__reactBoundContext = component; boundMethod.__reactBoundMethod = method; diff --git a/src/core/__tests__/ReactCompositeComponentError-test.js b/src/core/__tests__/ReactCompositeComponentError-test.js index 587ebe53f1..049af8a37c 100644 --- a/src/core/__tests__/ReactCompositeComponentError-test.js +++ b/src/core/__tests__/ReactCompositeComponentError-test.js @@ -26,7 +26,7 @@ var ReactErrorUtils = require('ReactErrorUtils'); describe('ReactCompositeComponent-error', function() { it('should be passed the component and method name', function() { - spyOn(ReactErrorUtils, 'guard'); + spyOn(ReactErrorUtils, 'guard').andCallThrough(); var Component = React.createClass({ someHandler: function() {}, render: function() {