diff --git a/_posts/2013-07-02-react-v0-4-autobind-by-default.md b/_posts/2013-07-02-react-v0-4-autobind-by-default.md new file mode 100644 index 00000000..9a5735f7 --- /dev/null +++ b/_posts/2013-07-02-react-v0-4-autobind-by-default.md @@ -0,0 +1,52 @@ +--- +title: "New in React v0.4: Autobind by Default" +layout: post +author: Paul O'Shannessy +--- + +React v0.4 is very close to completion. As we finish it off, we'd like to share with you some of the major changes we've made since v0.3. This is the first of several posts we'll be making over the next week. + + +## What is React.autoBind? + +If you take a look at most of our current examples, you'll see us using `React.autoBind` for event handlers. This is used in place of `Function.prototype.bind`. Remember that in JS, [function calls are late-bound](http://bonsaiden.github.io/JavaScript-Garden/#function.this). That means that if you simply pass a function around, the `this` used inside won't necessarily be the `this` you expect. `Function.prototype.bind` creates a new, properly bound, function so that when called, `this` is exactly what you expect it to be. + +Before we launched React, we would write this: + +```js{4} +React.createClass({ + onClick: function(event) {/* do something with this */}, + render: function() { + return