Skip to content

Commit

Permalink
tighten up isMethodContext checks, document it
Browse files Browse the repository at this point in the history
  • Loading branch information
andrasq committed Mar 7, 2020
1 parent 5b4c4c8 commit 769c135
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ Objects
Test whether the object is a generic hash `{}` ie `new Object()`, or is an instance of some
class. Tests the object constructor.

### qibl.isMethodContext( _this )

Test whether the given `this` is from a global (function call) context or a method call context.
Method calls have a `this` object that is not `global` and not `qibl`.

### qibl.copyObject( target, src1, ... )

Assign all enumerable own properties of the sources `src` onto `target`, and return
Expand Down
2 changes: 1 addition & 1 deletion qibl.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ function isHash( obj ) {
}

function isMethodContext( self ) {
return self && self !== qibl && self !== global || false;
return self && typeof self === 'object' && self !== qibl && self !== global || false;
}

// transfer the own properties of src onto target, aka Object.assign
Expand Down
2 changes: 2 additions & 0 deletions test-qibl.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ module.exports = {
t.equal(qibl.isMethodContext(qibl), false);
t.equal(qibl.isMethodContext(global), false);
t.equal(qibl.isMethodContext({}), true);
t.equal(qibl.isMethodContext(123), false);
t.equal(qibl.isMethodContext("string"), false);

var isMc = qibl.isMethodContext;
t.equal(isMc(), false);
Expand Down

0 comments on commit 769c135

Please sign in to comment.