Compare Revisions

Function.prototype.bind()

Change Revisions

Revision 417159:

Revision 417159 by Sheppy on

Revision 440971:

Revision 440971 by Gelus on

Title:
Function.prototype.bind
Function.prototype.bind
Slug:
Web/JavaScript/Reference/Global_Objects/Function/bind
Web/JavaScript/Reference/Global_Objects/Function/bind
Tags:
"ECMAScript5", "JavaScript 1.8.5", "Functions", "JavaScript"
"ECMAScript5", "JavaScript 1.8.5", "Functions", "JavaScript"
Content:

Revision 417159
Revision 440971
tt369    <p>
370      &nbsp;
371    </p>
372    <p>
373      <code style="font-size: 14px;">Function.prototype.bind</cod
 >e><span style="line-height: 21px;">&nbsp;is an ECMAScript 5 addit
 >ion; as such it may not be present in other implementations of th
 >e standard. You can work around this by inserting the following c
 >ode at the beginning of your scripts, allowing use of&nbsp;</span
 >><code style="font-size: 14px;">bind</code><span style="line-heig
 >ht: 21px;">&nbsp;in implementations which do not natively support
 > it.</span>
374    </p>
375    <pre class="brush: js">
376<span style="line-height: 1.572;">if(!function(){}.bind){</span>
377<span style="line-height: 1.572;">  Function.prototype.bind = fun
 >ction(){</span>
378    var me = this
379    ,<span class="Apple-tab-span" style="white-space:pre"> </span
 >>shift = [].shift
380    ,<span class="Apple-tab-span" style="white-space:pre"> </span
 >>he = shift.apply(arguments)
381    , ar = arguments
382    return function(){
383      me.apply(he, ar);
384    }
385  }
386}
387</pre>

Back to History