I am playing around with javascript, so it might sound as a trivial question. In a piece of code like this:
function timeFunction(fn, nameOfFn){
var start = Date.now();
fn();
var end = Date.now();
var time = end - start;
console.log(nameOfFn + ' took ' + time + 'ms');
}
function Person(name){
this.name = name;
this.sayName = function(){
console.log(this.name);
}
}
var bob = new Person('bob');
timeFunction(bob.sayName,'sayName');
Output is:
result
sayName took 7ms
(time will differ everytime you run the code)
Not sure where 'result' comes from and why 'Bob' is not shown.
resultin the console when I run that code - are you doing anything else?