Ver Mensaje Individual
  #9 (permalink)  
Antiguo 05/02/2011, 10:19
Avatar de masterpuppet
masterpuppet
Software Craftsman
 
Fecha de Ingreso: enero-2008
Ubicación: Montevideo, Uruguay
Mensajes: 3.550
Antigüedad: 16 años, 3 meses
Puntos: 845
Respuesta: Crear objeto THIS

salbatore se podria mejorar e implementar un bind como hacen las librerias(Mootools, Prototype, etc...), algo asi:

Código Javascript:
Ver original
  1. Function.prototype.bind = function(scope)
  2. {
  3.     var _function = this;  
  4.     return function() {
  5.         return _function.apply(scope, arguments);
  6.     }
  7. }
  8.  
  9. //ej 1
  10. var fn = function(){
  11.     alert(this);
  12. }.bind(objetos);
  13. fn();
  14.  
  15. //ej 2
  16. for(var i in objetos)
  17. {
  18.     (function(){
  19.         alert(this.className);
  20.     }.bind(objetos[i]))();
  21. }

Saludos.
__________________
http://es.phptherightway.com/
thats us riders :)