Skip to content
Open
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
15 changes: 9 additions & 6 deletions js2.html
Original file line number Diff line number Diff line change
Expand Up @@ -330,12 +330,15 @@ <h2>7. bind</h2>
<p><strong>Question:</strong> If an older browser dont have bind function, how will you shim it</p>
<p><strong>Answer:</strong> Look at the code below and use your brain.</p>
<pre><code>
Function.prototype.bind = Function.prototype.bind || function(context){
var self = this;
return function(){
return self.apply(context, arguments);
};
}
Function.prototype.bind = Function.prototype.bind || function (context) {
let prevArgs = [].slice.call(arguments, 1);

return () => {
let currentArgs = [].slice.call(arguments);
let combinedArgs = [].concat(prevArgs, currentArgs);
return this.apply(context, combinedArgs);
};
};
</code></pre>
</div>
<div id="call">
Expand Down