Skip to content

Instantly share code, notes, and snippets.

@boton
Created August 23, 2011 01:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save boton/1164067 to your computer and use it in GitHub Desktop.
Save boton/1164067 to your computer and use it in GitHub Desktop.
var Autobot = function(nombre){
this.nombre = nombre;
this.timer = +new Date();
};
Autobot.prototype.saludar = function() {
alert('Hola, me llamo '+ this.nombre + '\nTime: ' + (+new Date() - this.timer) + 'ms' );
};
Autobot.prototype.saludoDelay = function(ms){
var that = this;
setTimeout(function(){that.saludar();}, ms);
};
var optimus = new Autobot('Optimus Prime');
optimus.saludoDelay(100);
optimus.saludoDelay(10000);
@felixzapata
Copy link

Pues fíjate que probé esta solución y no me funcionó... cosa que me extrañó

@boton
Copy link
Author

boton commented Aug 23, 2011

@felixzapata a mi me funciono sin problemas ff, chrome, ie8... por lo que lei a posteriori, en ie6 peta pero no me preocupa, aunque vi alguna solución muy sucia almacenado datos en variables globales...

@felixzapata
Copy link

estuve probando únicamente en Firefox. Debí dejarme algo para que diera un fallo. Por eso opté por la otra

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment