Quote (kdog3682 @ Dec 6 2019 04:14am)
The code doesn't seem to work for:
Code
function doSomething(a, b) {
return a + b
}
Also, should new Date() be Date.now() ?
Hi, yes, you can use Date.now() if you are going to count ms only.
If you want to manipulate dates, like printing exact date and time of execution, new Date() is a way to go since it has bunch of in-built functions added.
Now, about passing an arguments to a function that has been passed to another function, you can mock it on several ways.
But there is a cool thing
Function.prototype.bind() and you can go with it. You can read more about it here:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_objects/Function/bindIf you dont want to read documentation, and want to go straight to example, here is bind() usage in one simple example:
Code
function doSomething(number1, number2){
for (i = 0; i < number1; i++) {
}
for (i = 0; i < number2; i++) {
}
}
function timingTracker(passedFunction){
var start = performance.now();
passedFunction();
var end = performance.now();
console.log("Passed function took " + (end - start) + " milliseconds to execute.");
}
timingTracker(doSomething.bind(null, 500000, 200000));