javascript - Grab `this` from caller function object -
i have some code i'm invoking everywhere this.
screenshot.snap(this, $('.navbar-inner .container'));
in above code, this
object being passed in mocha.js. contains information current test name, file it's in, etc. use information name screenshot.
i want remove need pass in this
reference everywhere, no matter how try reach inside of snap
function, unable find information need.
var testcontext = exports.snap.caller; //.prototype? .this?
i have inspected exports.snap.caller.tostring()
, , function called in mocha test suite. did through debugging repl, , on further inspection see information can the properties of function instance, contains nothing calling function's this
.
is there way this, or stuck passing in this
argument every time call screenshot.snap
function?
you might able in before
block like:
var snap; before(function () { browser.get('https://angularjs.org'); snap = screenshot.snap.bind(this); });
and replace use of screenshot.snap(this, $('.navbar-inner .container'));
snap($('.navbar-inner .container');
depending on how this
pointer handled mocha, may need in beforeeach
loop instead.
Comments
Post a Comment