Skip to content

Commit

Permalink
Fixing an issue when the bound function is called as a constructor in…
Browse files Browse the repository at this point in the history
… ES3.
  • Loading branch information
ljharb committed May 5, 2014
1 parent a2e29c4 commit e20122d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ function bind(that) {
var binder = function () {
if (this instanceof bound) {
var result = target.apply(
that,
this,
args.concat(slice.call(arguments))
);
if (Object(result) === result) {
Expand Down
13 changes: 13 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,19 @@ test('with a context', function (t) {
st.end();
});

t.test('has the new instance\'s context when called as a constructor', function (st) {
var actualContext;
var expectedContext = { foo: 'bar' };
var namespace = {
Func: functionBind.call(function () {
actualContext = this;
}, expectedContext)
};
var result = new namespace.Func();
st.notEqual(actualContext, expectedContext);
st.end();
});

t.end();
});

Expand Down

0 comments on commit e20122d

Please sign in to comment.