I\'m reading this article about perils of trying to mimic OOP in JavaScript and there\'s the following:
In JavaScript, factory functions are simply co
I don't like these answers because they use the this keyword. You can avoid this altogether and still use a factory function like this:
function createRabbit() {
var speed = 3;
return {
getSpeed: function() {
return speed;
}
}
}
var rabbit = createRabbit();
console.log(rabbit.getSpeed());
This guy has a good article about it: http://radar.oreilly.com/2014/03/javascript-without-the-this.html