-
Notifications
You must be signed in to change notification settings - Fork 10.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Replace unnecessary bind(this)
statements with arrow functions in web/
files
#8377
Conversation
…web/` files By using `let`, which is block-scoped, instead of `var` in a couple of places we're able to get rid of additional `bind` calls.
/botio-windows preview |
From: Bot.io (Windows)ReceivedCommand cmd_preview from @yurydelendik received. Current queue size: 0 Live output at: http://54.215.176.217:8877/cb3b4770d8aca19/output.txt |
From: Bot.io (Windows)SuccessFull output at http://54.215.176.217:8877/cb3b4770d8aca19/output.txt Total script time: 19.74 mins Published |
@@ -383,8 +383,8 @@ var PDFViewer = (function pdfViewer() { | |||
return; | |||
} | |||
var getPagesLeft = pagesCount; | |||
for (var pageNum = 1; pageNum <= pagesCount; ++pageNum) { | |||
pdfDocument.getPage(pageNum).then(function(pageNum, pdfPage) { | |||
for (let pageNum = 1; pageNum <= pagesCount; ++pageNum) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this was just converted into "var" for translated code, do we need to move let inside for-block?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let make it for(var i = 1; i <= pagesCount; i++) { let pageNum = i;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unless I'm missing something, this shouldn't be a problem. Note that Babel converts a loop with let
into a loop over a function, thus creating the necessary closure; see e.g. this simple example.
The complete code, taken from the preview above, thus becomes:
onePageRenderedCapability.promise.then(function () {
if (_pdfjs.PDFJS.disableAutoFetch) {
pagesCapability.resolve();
return;
}
var getPagesLeft = pagesCount;
var _loop = function _loop(_pageNum) {
pdfDocument.getPage(_pageNum).then(function (pdfPage) {
var pageView = _this._pages[_pageNum - 1];
if (!pageView.pdfPage) {
pageView.setPdfPage(pdfPage);
}
_this.linkService.cachePageRef(_pageNum, pdfPage.ref);
if (--getPagesLeft === 0) {
pagesCapability.resolve();
}
});
};
for (var _pageNum = 1; _pageNum <= pagesCount; ++_pageNum) {
_loop(_pageNum);
}
});
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
okay, nvm, I looked at wrong place
Thank you for the patch. |
Replace unnecessary `bind(this)` statements with arrow functions in `web/` files
By using
let
, which is block-scoped, instead ofvar
in a couple of places we're able to get rid of additionalbind
calls.