I wrote a code to solve this keyword issues in setTimeout() function. And tried to run it in node and it showed throw err; can't find module error. Then I tried to run it in a browser and it worked. I mean how to know when to test our code in nodejs and when not. This is my code
function person () {
var firstName ;
var _this_ = this;
return {
saveContext: function(context) {
_this_ = context;
},
setName: function(name) {
_this_.firstName = name;
},
getName: function() {
console.log(_this_.firstName);
}
};
}
var employee1 = new person();
employee1.saveContext(employee1);
employee1.setName('Steve');
employee1.getName();
setTimeout(employee1.getName, 1000);