diff --git a/documentation/index.html.erb b/documentation/index.html.erb index a4c3cb1b..b6cd8493 100644 --- a/documentation/index.html.erb +++ b/documentation/index.html.erb @@ -649,6 +649,14 @@ coffee --print app/scripts/*.coffee > concatenation.js

Function binding + In JavaScript, the this keyword is dynamically scoped to mean the + object that the current function is attached to. If you pass a function as + as callback, or attach it to a different object, the original value of this + will be lost. If you're not familiar with this behavior, + this Digital Web article + gives a good overview of the quirks. +

+

The fat arrow => can be used to both define a function, and to bind it to the current value of this, right on the spot. This is helpful when using callback-based libraries like Prototype or jQuery, for creating @@ -657,6 +665,11 @@ coffee --print app/scripts/*.coffee > concatenation.js properties of the this where they're defined.

<%= code_for('fat_arrow') %> +

+ If we had used -> in the callback above, @customer would + have referred to the undefined "customer" property of the DOM element, + and trying to call purchase() on it would have raised an exception. +

diff --git a/index.html b/index.html index bce68daf..3e0d75cb 100644 --- a/index.html +++ b/index.html @@ -1400,6 +1400,14 @@ city = _c[1];

Function binding + In JavaScript, the this keyword is dynamically scoped to mean the + object that the current function is attached to. If you pass a function as + as callback, or attach it to a different object, the original value of this + will be lost. If you're not familiar with this behavior, + this Digital Web article + gives a good overview of the quirks. +

+

The fat arrow => can be used to both define a function, and to bind it to the current value of this, right on the spot. This is helpful when using callback-based libraries like Prototype or jQuery, for creating @@ -1427,6 +1435,11 @@ Account = function this)); };
+

+ If we had used -> in the callback above, @customer would + have referred to the undefined "customer" property of the DOM element, + and trying to call purchase() on it would have raised an exception. +