Comment on Stanford's CS 101 course uses JavascriptparentComments−__rkaup__15yAre you saying im.getWidth() is doing some expensive calculation underneath, or that the cost of calling it is expensive in Javascript?−__mark15yI imagine it loops though the full width of the image every time it is called, which is every time the loop reaches the check.Since storing it will require width-1 less calls to im.getWidth() it is much more efficient no matter how you slice it.
Comments
Are you saying im.getWidth() is doing some expensive calculation underneath, or that the cost of calling it is expensive in Javascript?
I imagine it loops though the full width of the image every time it is called, which is every time the loop reaches the check.
Since storing it will require width-1 less calls to im.getWidth() it is much more efficient no matter how you slice it.